Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update to ESP8266HTTPClient.cpp for no Content-Length#7691

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
earlephilhower merged 9 commits intoesp8266:masterfromdrderiv:master
Nov 20, 2020

Conversation

@drderiv
Copy link
Contributor

@drderivdrderiv commentedNov 4, 2020
edited by d-a-v
Loading

Response bodies are ignored when _transferEncoding == HTTPC_TE_IDENTITY and there is no Content-Length header. The added code here attempts to fix that issue by writing the response body based upon how much content is available to be read.

edit:
Fixes#7692

Response bodies are ignored when _transferEncoding == HTTPC_TE_IDENTITY and there is no Content-Length header.  The added code here fixes that issue.
Copy link
Collaborator

@earlephilhowerearlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Little minor refactor, please.

Copy link
Collaborator

@earlephilhowerearlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the cleanup.

@d-a-v
Copy link
Collaborator

Now that it's working but with an unwilling timeout, you can updatewritetostreamdatablock() for it to stop when it can no longer read from the_client.
This is an old fashion function. A that time there were usually several attempts to read or write before giving up. Today one attempt and timeout checking is enough. This is addressed by#6979.
In the meantime, what is missing there is checking peer connectivity. That is answering to that question:
Is it possible to get more incoming data ? One just need to check_client's::available()==0and (::connected()==false or::status() != WL_CONNECTED). When this is true, it is no longer useful to wait for the timeout, peer has closed the connection and everything that is to be read is already swallowed.

@d-a-vd-a-v added this to the3.0.0 milestoneNov 16, 2020
@d-a-vd-a-v added the waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed. labelNov 16, 2020
@drderiv
Copy link
ContributorAuthor

With apologies, I'm not seeing how this would help, at least in the current implementations ofHTTPClient andStream. My reading is that, in a no Content-Length scenario (solen = -1), oncereadBytes() is called, the timeout controls, regardless of anything else. If that's correct, checking peer or wifi connectivity withinwriteToStreamDataBlock would not be useful. Changes to address this would need to occur within Stream, and thenwriteToStreamDataBlock would need to be modified to check the parameters you mention. In addition, I would still think a timeout would be needed (and it would have to be added towriteToStreamDataBlock as well) in the case where you remain connected but the server just decides to take a nap.

Perhaps the word 'meantime' threw me and you are asking for theHTTPClient mods prospectively to work with the changes to Stream implemented in#6979?

@d-a-v
Copy link
Collaborator

d-a-v commentedNov 16, 2020
edited
Loading

In#6979,writetostreamdatablockis removed and replaced byStream::to() - having both timeout and end of stream detection - but still lacks from maintainers's review because it was introducingStream:: inheritance toString::, now removed, that was considered by some as a blaspheme, which I still don't understand why ;) Maybe I should repost it with another name and its history expunged of the heresy.

But before#6979 is considered, a fix is needed for your issue, and#7692 too which is the same issue.

End of TCP connection cannot currently be handled byStream:: so it has to bewritetostreamdatablock()'s job. While examining#7692 I ended up with the following and stopped there because I was too optimistic regarding#6979 consideration. You may try it. The logic is the following: do not ask too much toStream::readBytes() because that one will wait until timeout that all requested data are received. Instead ask for what's already there and keep retrying until all data are received.

+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp@@ -725,7 +725,7 @@ int HTTPClient::writeToStream(Stream * stream)     int ret = 0;      if(_transferEncoding == HTTPC_TE_IDENTITY) {-        if(len > 0) {+        if(len > 0 || len == -1) {             ret = writeToStreamDataBlock(stream, len);              // have we an error?@@ -1184,6 +1184,9 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size)         if(readBytes > buff_size) {             readBytes = buff_size;         }+        int av = _client->available();+        if (readBytes < 0 || readBytes > av)+            readBytes = av;          // read data

If this works for you, please update your PR.

Add logic to writeToStreamDataBlock to only read what's available so as to avoid timeout, and adjust formatting.
@drderiv
Copy link
ContributorAuthor

That worked nicely. And now I understand what you meant about effectively checking_client's::available()==0 and::connected()==false. The idea about reading what's already there was what I was trying to do -- poorly, as I didn't include the 'until all data are received' part -- in my initial PR. With your help, I think we've now got it right. Thanks again.

@earlephilhowerearlephilhower merged commit47a57e1 intoesp8266:masterNov 20, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@earlephilhowerearlephilhowerearlephilhower approved these changes

@d-a-vd-a-vd-a-v approved these changes

Assignees

No one assigned

Labels

waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed.

Projects

None yet

Milestone

3.0.0

Development

Successfully merging this pull request may close these issues.

http.getString() return blank

3 participants

@drderiv@d-a-v@earlephilhower

[8]ページ先頭

©2009-2025 Movatter.jp