Skip to content

Commit ef748e3

Browse files
committed
allow downgrade to HTTP 1.0
use HTTP/1.0 for update since the update handler not support any transfer Encoding
1 parent b828f34 commit ef748e3

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ HTTPClient::HTTPClient() {
4141

4242
_reuse = false;
4343
_tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
44+
_useHTTP10 = false;
4445

4546
_https = false;
4647

@@ -266,6 +267,16 @@ void HTTPClient::setTimeout(uint16_t timeout) {
266267
}
267268
}
268269

270+
271+
272+
/**
273+
* use HTTP1.0
274+
* @param timeout
275+
*/
276+
void HTTPClient::useHTTP10(bool useHTTP10) {
277+
_useHTTP10 = useHTTP10;
278+
}
279+
269280
/**
270281
* send a GET request
271282
* @return http code
@@ -757,10 +768,17 @@ bool HTTPClient::sendHeader(const char * type) {
757768
return false;
758769
}
759770

760-
String header = String(type) + " " + _url + " HTTP/1.1\r\n"
771+
String header = String(type) + " " + _url + " HTTP/1.";
772+
773+
if(_useHTTP10) {
774+
header += "0";
775+
} else {
776+
header += "1";
777+
}
778+
779+
header += "\r\n"
761780
"Host: " + _host + "\r\n"
762781
"User-Agent: " + _userAgent + "\r\n"
763-
"Accept-Encoding: identity;q=1 chunked;q=0.1 *;q=0\r\n"
764782
"Connection: ";
765783

766784
if(_reuse) {
@@ -770,6 +788,10 @@ bool HTTPClient::sendHeader(const char * type) {
770788
}
771789
header += "\r\n";
772790

791+
if(!_useHTTP10) {
792+
header += "Accept-Encoding: identity;q=1 chunked;q=0.1 *;q=0\r\n";
793+
}
794+
773795
if(_base64Authorization.length()) {
774796
header += "Authorization: Basic " + _base64Authorization + "\r\n";
775797
}

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class HTTPClient {
137137
void setAuthorization(const char * auth);
138138
void setTimeout(uint16_t timeout);
139139

140+
void useHTTP10(bool usehttp10 = true);
141+
140142
/// request handling
141143
int GET();
142144
int POST(uint8_t * payload, size_t size);
@@ -180,6 +182,7 @@ class HTTPClient {
180182
uint16_t _port;
181183
bool _reuse;
182184
uint16_t _tcpTimeout;
185+
bool _useHTTP10;
183186

184187
String _url;
185188
bool _https;

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
146146

147147
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
148148

149+
// use HTTP/1.0 for update since the update handler not support any transfer Encoding
150+
http->useHTTP10(true);
151+
http->setTimeout(8000);
149152
http->setUserAgent("ESP8266-http-Update");
150153
http->addHeader("x-ESP8266-STA-MAC", WiFi.macAddress());
151154
http->addHeader("x-ESP8266-AP-MAC", WiFi.softAPmacAddress());

0 commit comments

Comments
 (0)