Skip to content

Fix header parsing #4455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions libraries/HTTPClient/src/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,23 +1186,32 @@ int HTTPClient::handleHeaderResponse()

_transferEncoding = HTTPC_TE_IDENTITY;
unsigned long lastDataTime = millis();

String headerLine = _client->readStringUntil('\n');
headerLine.trim(); // remove \r

lastDataTime = millis();

log_v("RX: '%s'", headerLine.c_str());

if(headerLine.startsWith("HTTP/1.")) {
if(_canReuse) {
_canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0');
}
}
_returnCode = headerLine.substring(headerLine.indexOf(' ')).toInt();

while(connected()) {
size_t len = _client->available();
if(len > 0) {
String headerLine = _client->readStringUntil('\n');
headerLine = _client->readStringUntil('\n');
headerLine.trim(); // remove \r

lastDataTime = millis();

log_v("RX: '%s'", headerLine.c_str());

if(headerLine.startsWith("HTTP/1.")) {
if(_canReuse) {
_canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0');
}
_returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt();
} else if(headerLine.indexOf(':')) {
if(headerLine.indexOf(':')) {
String headerName = headerLine.substring(0, headerLine.indexOf(':'));
String headerValue = headerLine.substring(headerLine.indexOf(':') + 1);
headerValue.trim();
Expand Down Expand Up @@ -1450,4 +1459,4 @@ bool HTTPClient::setURL(const String& url)
const String &HTTPClient::getLocation(void)
{
return _location;
}
}