Skip to content

Commit db1cfc7

Browse files
liebmanigrr
authored andcommitted
handle empty uri
http.begin("http://www.google.com") yields an empty uri and makes a broken request "GET HTTPi/1.1"
1 parent 4c08389 commit db1cfc7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class TransportTraits
4444

4545
virtual bool verify(WiFiClient& client, const char* host)
4646
{
47+
(void)client;
48+
(void)host;
4749
return true;
4850
}
4951
};
@@ -167,6 +169,7 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
167169
_host = host;
168170
}
169171
_uri = url;
172+
170173
if (_protocol != expectedProtocol) {
171174
DEBUG_HTTPCLIENT("[HTTP-Client][begin] unexpected protocol: %s, expected %s\n", _protocol.c_str(), expectedProtocol);
172175
return false;
@@ -871,7 +874,7 @@ bool HTTPClient::sendHeader(const char * type)
871874
return false;
872875
}
873876

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

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

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

914+
DEBUG_HTTPCLIENT("[HTTP-Client] sending request header\n-----\n%s-----\n", header.c_str());
915+
911916
return (_tcp->write((const uint8_t *) header.c_str(), header.length()) == header.length());
912917
}
913918

0 commit comments

Comments
 (0)