mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
ESP8266HTTPClient: fix duplicate Content-Length headers (#1902)
This commit is contained in:
parent
d1fc7002c1
commit
dd81336b79
@ -706,19 +706,27 @@ String HTTPClient::errorToString(int error)
|
|||||||
* @param value
|
* @param value
|
||||||
* @param first
|
* @param first
|
||||||
*/
|
*/
|
||||||
void HTTPClient::addHeader(const String& name, const String& value, bool first)
|
void HTTPClient::addHeader(const String& name, const String& value, bool first, bool replace)
|
||||||
{
|
{
|
||||||
|
|
||||||
// not allow set of Header handled by code
|
// not allow set of Header handled by code
|
||||||
if(!name.equalsIgnoreCase(F("Connection")) &&
|
if(!name.equalsIgnoreCase(F("Connection")) &&
|
||||||
!name.equalsIgnoreCase(F("User-Agent")) &&
|
!name.equalsIgnoreCase(F("User-Agent")) &&
|
||||||
!name.equalsIgnoreCase(F("Host")) &&
|
!name.equalsIgnoreCase(F("Host")) &&
|
||||||
!(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())){
|
!(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())){
|
||||||
|
|
||||||
String headerLine = name;
|
String headerLine = name;
|
||||||
headerLine += ": ";
|
headerLine += ": ";
|
||||||
|
|
||||||
|
if (replace) {
|
||||||
|
int headerStart = _headers.indexOf(headerLine);
|
||||||
|
if (headerStart != -1) {
|
||||||
|
int headerEnd = _headers.indexOf('\n', headerStart);
|
||||||
|
_headers = _headers.substring(0, headerStart) + _headers.substring(headerEnd + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
headerLine += value;
|
headerLine += value;
|
||||||
headerLine += "\r\n";
|
headerLine += "\r\n";
|
||||||
|
|
||||||
if(first) {
|
if(first) {
|
||||||
_headers = headerLine + _headers;
|
_headers = headerLine + _headers;
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,7 +160,7 @@ public:
|
|||||||
int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0);
|
int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0);
|
||||||
int sendRequest(const char * type, Stream * stream, size_t size = 0);
|
int sendRequest(const char * type, Stream * stream, size_t size = 0);
|
||||||
|
|
||||||
void addHeader(const String& name, const String& value, bool first = false);
|
void addHeader(const String& name, const String& value, bool first = false, bool replace = true);
|
||||||
|
|
||||||
/// Response handling
|
/// Response handling
|
||||||
void collectHeaders(const char* headerKeys[], const size_t headerKeysCount);
|
void collectHeaders(const char* headerKeys[], const size_t headerKeysCount);
|
||||||
|
@ -6,3 +6,4 @@
|
|||||||
#define AP_SSID "test_wifi_ap"
|
#define AP_SSID "test_wifi_ap"
|
||||||
#define AP_PASS "test_wifi_ap_pass"
|
#define AP_PASS "test_wifi_ap_pass"
|
||||||
|
|
||||||
|
#define SERVER_IP "192.168.10.1"
|
||||||
|
@ -21,7 +21,7 @@ void setup()
|
|||||||
|
|
||||||
const char* fp = "40 A3 6C E3 8A DF A2 D4 13 B0 32 5C 87 44 54 28 0B CE C5 A4";
|
const char* fp = "40 A3 6C E3 8A DF A2 D4 13 B0 32 5C 87 44 54 28 0B CE C5 A4";
|
||||||
|
|
||||||
TEST_CASE("HTTP GET request", "[HTTPClient]")
|
TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// small request
|
// small request
|
||||||
@ -47,7 +47,20 @@ TEST_CASE("HTTP GET request", "[HTTPClient]")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// can do two POST requests with one HTTPClient object (#1902)
|
||||||
|
HTTPClient http;
|
||||||
|
http.begin(SERVER_IP, 8088, "/");
|
||||||
|
http.addHeader("Content-Type", "text/plain");
|
||||||
|
auto httpCode = http.POST("foo");
|
||||||
|
Serial.println(httpCode);
|
||||||
|
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||||
|
http.end();
|
||||||
|
|
||||||
|
httpCode = http.POST("bar");
|
||||||
|
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||||
|
http.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,57 +92,6 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// TEST_CASE("HTTP GET request", "[HTTPClient]")
|
|
||||||
// {
|
|
||||||
// const int repeatCount = 10;
|
|
||||||
|
|
||||||
// String url = createBin(false);
|
|
||||||
// int heapBefore = ESP.getFreeHeap();
|
|
||||||
// for (int i = 0; i < repeatCount; ++i) {
|
|
||||||
// HTTPClient http;
|
|
||||||
// http.begin(url);
|
|
||||||
// auto httpCode = http.GET();
|
|
||||||
// REQUIRE(httpCode == HTTP_CODE_OK);
|
|
||||||
// String payload = http.getString();
|
|
||||||
// payload.replace("\n", "\\n");
|
|
||||||
// String quotedPayload;
|
|
||||||
// quotedPayload.reserve(payload.length() + 3);
|
|
||||||
// quotedPayload += "\"";
|
|
||||||
// quotedPayload += payload;
|
|
||||||
// quotedPayload += "\"";
|
|
||||||
// Serial.println("----payload:");
|
|
||||||
// Serial.println(quotedPayload);
|
|
||||||
// Serial.println("----");
|
|
||||||
// Serial.println("----test_payload:");
|
|
||||||
// Serial.println(test_payload);
|
|
||||||
// Serial.println("----");
|
|
||||||
// CHECK(quotedPayload == test_payload);
|
|
||||||
// http.end();
|
|
||||||
// delay(100);
|
|
||||||
// }
|
|
||||||
// int heapAfter = ESP.getFreeHeap();
|
|
||||||
// CHECK(heapBefore - heapAfter <= 8);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// TEST_CASE("HTTPS GET request", "[HTTPClient]")
|
|
||||||
// {
|
|
||||||
// const int repeatCount = 10;
|
|
||||||
|
|
||||||
// String url = createBin(true);
|
|
||||||
// int heapBefore = ESP.getFreeHeap();
|
|
||||||
// for (int i = 0; i < repeatCount; ++i) {
|
|
||||||
// HTTPClient http;
|
|
||||||
// http.begin(url, mockbin_fingerprint);
|
|
||||||
// auto httpCode = http.GET();
|
|
||||||
// REQUIRE(httpCode == HTTP_CODE_OK);
|
|
||||||
// String payload = http.getString();
|
|
||||||
// CHECK(payload == test_payload);
|
|
||||||
// http.end();
|
|
||||||
// delay(100);
|
|
||||||
// }
|
|
||||||
// int heapAfter = ESP.getFreeHeap();
|
|
||||||
// CHECK(heapBefore - heapAfter <= 8);
|
|
||||||
// }
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ import urllib2
|
|||||||
import os
|
import os
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
@setup('HTTP GET request')
|
@setup('HTTP GET & POST requests')
|
||||||
def setup_http_get(e):
|
def setup_http_get(e):
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
def shutdown_server():
|
def shutdown_server():
|
||||||
@ -17,8 +17,9 @@ def setup_http_get(e):
|
|||||||
def shutdown():
|
def shutdown():
|
||||||
shutdown_server()
|
shutdown_server()
|
||||||
return 'Server shutting down...'
|
return 'Server shutting down...'
|
||||||
@app.route("/")
|
@app.route("/", methods = ['GET', 'POST'])
|
||||||
def root():
|
def root():
|
||||||
|
print('Got data: ' + request.data);
|
||||||
return 'hello!!!'
|
return 'hello!!!'
|
||||||
@app.route("/data")
|
@app.route("/data")
|
||||||
def get_data():
|
def get_data():
|
||||||
@ -29,7 +30,7 @@ def setup_http_get(e):
|
|||||||
th = Thread(target=flaskThread)
|
th = Thread(target=flaskThread)
|
||||||
th.start()
|
th.start()
|
||||||
|
|
||||||
@teardown('HTTP GET request')
|
@teardown('HTTP GET & POST requests')
|
||||||
def teardown_http_get(e):
|
def teardown_http_get(e):
|
||||||
response = urllib2.urlopen('http://localhost:8088/shutdown')
|
response = urllib2.urlopen('http://localhost:8088/shutdown')
|
||||||
html = response.read()
|
html = response.read()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user