From db1cfc77729134a9b5b74047255663c7bd97ac29 Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Mon, 4 Dec 2017 12:24:08 -0800 Subject: [PATCH] handle empty uri http.begin("http://www.google.com") yields an empty uri and makes a broken request "GET HTTPi/1.1" --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index ef4c55157..0abc66fa4 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -44,6 +44,8 @@ public: virtual bool verify(WiFiClient& client, const char* host) { + (void)client; + (void)host; return true; } }; @@ -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; @@ -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"; @@ -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()); }