Skip to content
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

Add support for HTTP/1.0 responses without 'Content-Lenght' header #403

Merged
merged 2 commits into from
Nov 3, 2023
Merged

Add support for HTTP/1.0 responses without 'Content-Lenght' header #403

merged 2 commits into from
Nov 3, 2023

Conversation

oleneveu
Copy link
Contributor

@oleneveu oleneveu commented Nov 3, 2023

Description

  • Modified InputNetworkStream.InternalRead() to detect the cases when in http 1.0 and the connection is closed.
  • Reused interface IKnownWhenDone (originally only for chunked encoding) to pass the information to the caller (StreamContent).
  • Modified StreamContent to take in account the last bytes returned by InputNetworkStream.Read() when IKnownWhenDone.IsDone == true (was always 0 with chunked encoding).

Motivation and Context

Both HttpClient and HttpWebRequest does not handle case where the server does not include a Content-Length and closes the connection to mark the end of the body.

How Has This Been Tested?

Changes tested against several http servers with an ESP32 in debug mode, using HttpClient and HttpWebRequest.
Response was written to VS output and compared to the response captured using 'Telerik Fiddler'.

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

@oleneveu
Copy link
Contributor Author

oleneveu commented Nov 3, 2023

@dotnet-policy-service agree

Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

WOW! Glad to see that you've found your way through this and a solution. 🥳
Just a tiny change.

@josesimoes josesimoes changed the title Add HTTP/1.0 style responses handling (no 'Content-Lenght' header) Add support for HTTP/1.0 responses without 'Content-Lenght' header Nov 3, 2023
@josesimoes josesimoes enabled auto-merge (squash) November 3, 2023 17:46
@josesimoes josesimoes merged commit e268ac0 into nanoframework:main Nov 3, 2023
6 checks passed
@nfbot
Copy link
Member

nfbot commented Nov 3, 2023

@oleneveu thank you again for your contribution! 🙏😄

.NET nanoFramework it's all about community involvement and no contribution is too small.
We would like to invite you to join the project Contributors list.

Please edit it and add an entry with your GitHub user in the appropriate location (names sorted alphabetically):

  <tr>
    <td><img src="https://github.com/oleneveu.png?size=50&" height="50" width="50" ></td>
    <td><a href="https://github.com/oleneveu">Olivier Leneveu</a></td>
  </tr>

(feel free to adjust your name, if it's not correct)

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

Successfully merging this pull request may close these issues.

Http requests fails if the server response does not include a 'Content-Length' header
3 participants