-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Fix header parsing #4455
Conversation
Valid responses can have other content than HTTP1.x as first line. A valid response is e.g. "ICY 200 OK". This fix allows other responses. This makes it easy to use the client e.g. for streaming audio. fixes #4454
Any thoughts? |
It is no fun to contribute if there is not the slightest reaction. I know why I don't like ESP. |
Attitude and unrealistic expectations aside, I would suggest that you use a boolean |
The first line is, yes, the first line. No need to parse it inside a loop (Why should one do that? Slower than needed) Anyway, as long it gets fixed I don't care. |
I'll open a new PR, which will be slower and larger, as you requested 👍 |
Hm, nö, es widerstrebt mir zutiefst in der Schleife immer wieder auf den Header zu parsen. Ich mach das hier wieder auf :) |
change is exactly 4 lines. I'm not sure what you mean about slower and larger... bool firstLine = true;
while(connected()) {
size_t len = _client->available();
if(len > 0) {
String headerLine = _client->readStringUntil('\n');
headerLine.trim(); // remove \r
lastDataTime = millis();
log_v("RX: '%s'", headerLine.c_str());
if(firstLine) {
firstLine = false;
if(headerLine.startsWith("HTTP/1.") && _canReuse) {
_canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0');
}
int codePos = headerLine.indexOf(' ') + 1;
_returnCode = headerLine.substring(codePos, headerLine.indexOf(' ', codePos)).toInt();
} else if(headerLine.indexOf(':')) {
String headerName = headerLine.substring(0, headerLine.indexOf(':'));
String headerValue = headerLine.substring(headerLine.indexOf(':') + 1);
headerValue.trim();
|
Ok, if you like that more :) |
done :) |
Valid responses can have other content than HTTP1.x as first line. A valid response is e.g. "ICY 200 OK".
This fix allows other responses.
This makes it easy to use the client e.g. for streaming audio.
fixes #4454