From ef748e369a57cde938ab29689843a14a4087227b Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Thu, 31 Dec 2015 14:02:00 +0100 Subject: [PATCH] allow downgrade to HTTP 1.0 use HTTP/1.0 for update since the update handler not support any transfer Encoding --- .../src/ESP8266HTTPClient.cpp | 26 +++++++++++++++++-- .../ESP8266HTTPClient/src/ESP8266HTTPClient.h | 3 +++ .../src/ESP8266httpUpdate.cpp | 3 +++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 79923893a..b1558f3b6 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -41,6 +41,7 @@ HTTPClient::HTTPClient() { _reuse = false; _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT; + _useHTTP10 = false; _https = false; @@ -266,6 +267,16 @@ void HTTPClient::setTimeout(uint16_t timeout) { } } + + +/** + * use HTTP1.0 + * @param timeout + */ +void HTTPClient::useHTTP10(bool useHTTP10) { + _useHTTP10 = useHTTP10; +} + /** * send a GET request * @return http code @@ -757,10 +768,17 @@ bool HTTPClient::sendHeader(const char * type) { return false; } - String header = String(type) + " " + _url + " HTTP/1.1\r\n" + String header = String(type) + " " + _url + " HTTP/1."; + + if(_useHTTP10) { + header += "0"; + } else { + header += "1"; + } + + header += "\r\n" "Host: " + _host + "\r\n" "User-Agent: " + _userAgent + "\r\n" - "Accept-Encoding: identity;q=1 chunked;q=0.1 *;q=0\r\n" "Connection: "; if(_reuse) { @@ -770,6 +788,10 @@ bool HTTPClient::sendHeader(const char * type) { } header += "\r\n"; + if(!_useHTTP10) { + header += "Accept-Encoding: identity;q=1 chunked;q=0.1 *;q=0\r\n"; + } + if(_base64Authorization.length()) { header += "Authorization: Basic " + _base64Authorization + "\r\n"; } diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index 024a27064..aff0ff1ed 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -137,6 +137,8 @@ class HTTPClient { void setAuthorization(const char * auth); void setTimeout(uint16_t timeout); + void useHTTP10(bool usehttp10 = true); + /// request handling int GET(); int POST(uint8_t * payload, size_t size); @@ -180,6 +182,7 @@ class HTTPClient { uint16_t _port; bool _reuse; uint16_t _tcpTimeout; + bool _useHTTP10; String _url; bool _https; diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index f45846440..05b42ea8d 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -146,6 +146,9 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha t_httpUpdate_return ret = HTTP_UPDATE_FAILED; + // use HTTP/1.0 for update since the update handler not support any transfer Encoding + http->useHTTP10(true); + http->setTimeout(8000); http->setUserAgent("ESP8266-http-Update"); http->addHeader("x-ESP8266-STA-MAC", WiFi.macAddress()); http->addHeader("x-ESP8266-AP-MAC", WiFi.softAPmacAddress());