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

Fix header parsing #4455

wants to merge 2 commits into from

Conversation

FrankBoesing
Copy link
Contributor

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

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
@FrankBoesing
Copy link
Contributor Author

Any thoughts?

@FrankBoesing
Copy link
Contributor Author

It is no fun to contribute if there is not the slightest reaction.

I know why I don't like ESP.

@me-no-dev
Copy link
Member

Attitude and unrealistic expectations aside, I would suggest that you use a boolean responseHeadParsed or similar to properly parse the first line inside the while (thus having minimal code duplication).

@FrankBoesing
Copy link
Contributor Author

The first line is, yes, the first line. No need to parse it inside a loop (Why should one do that? Slower than needed)
Then, my Patch has minimal code duplication.

Anyway, as long it gets fixed I don't care.
Thanks.

@FrankBoesing
Copy link
Contributor Author

I'll open a new PR, which will be slower and larger, as you requested 👍

@FrankBoesing
Copy link
Contributor Author

Hm, nö, es widerstrebt mir zutiefst in der Schleife immer wieder auf den Header zu parsen.
Lieber einige (wenige!) Bytes mehr, als das.

Ich mach das hier wieder auf :)
Du hast schon gesehen, daß aus der Schleife jede Menge code entfernt wurde?

@FrankBoesing FrankBoesing reopened this Nov 2, 2020
@me-no-dev
Copy link
Member

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();

@FrankBoesing
Copy link
Contributor Author

Ok, if you like that more :)

@me-no-dev me-no-dev closed this in 704b71d Nov 2, 2020
@me-no-dev
Copy link
Member

done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Http Client does not accept "ICY 200 OK" as valid header
2 participants