Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append '/' to an URL with empty path in HTTPClient::begin #5634

Merged

Conversation

long-long-float
Copy link
Contributor

@long-long-float long-long-float commented Sep 5, 2021

Summary

Append '/' to an URL with empty path in HTTPClient::begin. For example, http.begin("http://example.com") is the same as http.begin("http://example.com/").

Add an error check for empty path of HTTPClient::begin. For example, http.begin("http://example.com") returns false because the path of it is empty (http.begin("http://example.com/") returns true).

RFC2616 and RFC2396 say this url is invalid. Furthermore, most servers return 400 Bad Request.

@CLAassistant
Copy link

CLAassistant commented Sep 5, 2021

CLA assistant check
All committers have signed the CLA.

@@ -261,6 +261,10 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
url.remove(0, (index + 3)); // remove http:// or https://

index = url.indexOf('/');
if (index == -1) {
log_e("the path of url must not be empty");
return false;
Copy link
Collaborator

@atanisoft atanisoft Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree a check is needed here to prevent using -1 for index, but I don't think it should be an error. If you type in "example.com" into a browser it defaults the path to / for you. Likely this code should do the same in this case. Perhaps something like this inside this new condition block:

  url += '/';
  index = url.indexOf('/');

It will incur the cost of calling indexOf a second time but I don't think there are many options around this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too. I'll fix this.

I don't think there are many options around this.

The method length can be also used.

@long-long-float long-long-float changed the title Add an error check for empty path of HTTPClient::begin Append '/' to an URL with empty path in HTTPClient::begin Sep 8, 2021
@me-no-dev me-no-dev merged commit 204f360 into espressif:master Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants