Skip to content

Commit

Permalink
handle empty uri
Browse files Browse the repository at this point in the history
http.begin("http://www.google.com") yields an empty uri and makes a broken request "GET  HTTPi/1.1"
  • Loading branch information
liebman authored and igrr committed Dec 26, 2017
1 parent 4c08389 commit db1cfc7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class TransportTraits

virtual bool verify(WiFiClient& client, const char* host)
{
(void)client;
(void)host;
return true;
}
};
Expand Down Expand Up @@ -167,6 +169,7 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
_host = host;
}
_uri = url;

if (_protocol != expectedProtocol) {
DEBUG_HTTPCLIENT("[HTTP-Client][begin] unexpected protocol: %s, expected %s\n", _protocol.c_str(), expectedProtocol);
return false;
Expand Down Expand Up @@ -871,7 +874,7 @@ bool HTTPClient::sendHeader(const char * type)
return false;
}

String header = String(type) + " " + _uri + F(" HTTP/1.");
String header = String(type) + " " + (_uri.length() ? _uri : F("/")) + F(" HTTP/1.");

if(_useHTTP10) {
header += "0";
Expand Down Expand Up @@ -908,6 +911,8 @@ bool HTTPClient::sendHeader(const char * type)

header += _headers + "\r\n";

DEBUG_HTTPCLIENT("[HTTP-Client] sending request header\n-----\n%s-----\n", header.c_str());

return (_tcp->write((const uint8_t *) header.c_str(), header.length()) == header.length());
}

Expand Down

0 comments on commit db1cfc7

Please sign in to comment.