requests: HTTP/1.1 with Content-Length and streaming raw#1124
Open
pablogventura wants to merge 5 commits into
Open
requests: HTTP/1.1 with Content-Length and streaming raw#1124pablogventura wants to merge 5 commits into
pablogventura wants to merge 5 commits into
Conversation
Introduce read_status_line(), read_headers(), and BodyStream with Content-Length and until-close modes. No request() changes yet. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
Wire _http into request(); send HTTP/1.1; return BodyStream as .raw without reading or closing the socket in request(). Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
Adapt outbound tests to HTTP/1.1; add Content-Length and incremental .raw.read() coverage. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
Document HTTP/1.1 requests and Content-Length body reads via .raw. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
Read part of the body via .raw then the remainder via .content; avoid "hel" token flagged by codespell. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
Author
ESP32 hardware testingTested on device connected via
Mock tests (
|
| Test | Result |
|---|---|
GET /get with Content-Length body |
200, 11 bytes |
GET /bytes/8 via .content |
abcdefgh, socket closed after read |
GET /bytes/10 incremental .raw.read(3) + .raw.read(3) + .raw.read() |
3+3+4 bytes → 0123456789 |
GET /chunked |
ValueError: Unsupported Transfer-Encoding: chunked (expected for v1) |
Server log confirmed outbound requests use HTTP/1.1:
GET /get HTTP/1.1
GET /bytes/8 HTTP/1.1
GET /bytes/10 HTTP/1.1
GET /chunked HTTP/1.1
Notes
httpbin.orgreturned 503 from this network, so live body tests used a local test server instead.- Mock tests replace
sys.modules["socket"]; live tests reloadusocketafterwards before hitting the network.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_httpmodule.Content-Lengthresponse bodies without buffering inrequest()..rawas a liveBodyStreamwrapper;.contentremains lazy.Closes the approach in #1119 (which buffered the full body and closed the socket). Chunked responses,
max_body, and relative redirects are intentionally left for follow-up PRs.Testing
micropython test_requests.py(unix port) — 13 mock tests including incremental.raw.read().Trade-offs and Alternatives
ValueError(unchanged from master until a follow-up PR).BodyStreamadds a small wrapper object (~two fields) instead of buffering the body inrequest().stream=Trueis not implemented yet (issue requests: stream parameter is noop #777).Generative AI
I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.