mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
allow downgrade to HTTP 1.0
use HTTP/1.0 for update since the update handler not support any transfer Encoding
This commit is contained in:
parent
b828f34348
commit
ef748e369a
@ -41,6 +41,7 @@ HTTPClient::HTTPClient() {
|
|||||||
|
|
||||||
_reuse = false;
|
_reuse = false;
|
||||||
_tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
|
_tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
|
||||||
|
_useHTTP10 = false;
|
||||||
|
|
||||||
_https = 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
|
* send a GET request
|
||||||
* @return http code
|
* @return http code
|
||||||
@ -757,10 +768,17 @@ bool HTTPClient::sendHeader(const char * type) {
|
|||||||
return false;
|
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"
|
"Host: " + _host + "\r\n"
|
||||||
"User-Agent: " + _userAgent + "\r\n"
|
"User-Agent: " + _userAgent + "\r\n"
|
||||||
"Accept-Encoding: identity;q=1 chunked;q=0.1 *;q=0\r\n"
|
|
||||||
"Connection: ";
|
"Connection: ";
|
||||||
|
|
||||||
if(_reuse) {
|
if(_reuse) {
|
||||||
@ -770,6 +788,10 @@ bool HTTPClient::sendHeader(const char * type) {
|
|||||||
}
|
}
|
||||||
header += "\r\n";
|
header += "\r\n";
|
||||||
|
|
||||||
|
if(!_useHTTP10) {
|
||||||
|
header += "Accept-Encoding: identity;q=1 chunked;q=0.1 *;q=0\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
if(_base64Authorization.length()) {
|
if(_base64Authorization.length()) {
|
||||||
header += "Authorization: Basic " + _base64Authorization + "\r\n";
|
header += "Authorization: Basic " + _base64Authorization + "\r\n";
|
||||||
}
|
}
|
||||||
|
@ -137,6 +137,8 @@ class HTTPClient {
|
|||||||
void setAuthorization(const char * auth);
|
void setAuthorization(const char * auth);
|
||||||
void setTimeout(uint16_t timeout);
|
void setTimeout(uint16_t timeout);
|
||||||
|
|
||||||
|
void useHTTP10(bool usehttp10 = true);
|
||||||
|
|
||||||
/// request handling
|
/// request handling
|
||||||
int GET();
|
int GET();
|
||||||
int POST(uint8_t * payload, size_t size);
|
int POST(uint8_t * payload, size_t size);
|
||||||
@ -180,6 +182,7 @@ class HTTPClient {
|
|||||||
uint16_t _port;
|
uint16_t _port;
|
||||||
bool _reuse;
|
bool _reuse;
|
||||||
uint16_t _tcpTimeout;
|
uint16_t _tcpTimeout;
|
||||||
|
bool _useHTTP10;
|
||||||
|
|
||||||
String _url;
|
String _url;
|
||||||
bool _https;
|
bool _https;
|
||||||
|
@ -146,6 +146,9 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
|
|||||||
|
|
||||||
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
|
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->setUserAgent("ESP8266-http-Update");
|
||||||
http->addHeader("x-ESP8266-STA-MAC", WiFi.macAddress());
|
http->addHeader("x-ESP8266-STA-MAC", WiFi.macAddress());
|
||||||
http->addHeader("x-ESP8266-AP-MAC", WiFi.softAPmacAddress());
|
http->addHeader("x-ESP8266-AP-MAC", WiFi.softAPmacAddress());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user