Skip to content

feat: add Request.read(size) method for partial body reading#3164

Open
Jagdish1115 wants to merge 2 commits intoKludex:mainfrom
Jagdish1115:feature/request-read-method
Open

feat: add Request.read(size) method for partial body reading#3164
Jagdish1115 wants to merge 2 commits intoKludex:mainfrom
Jagdish1115:feature/request-read-method

Conversation

@Jagdish1115
Copy link

@Jagdish1115 Jagdish1115 commented Feb 28, 2026

Summary

Adds a read(size) method to the Request class that reads exactly size bytes from the request body at a time. Currently there is no way to read a specific number of bytes from the request body. The only options are body() which loads everything into memory at once, or stream() which gives server-decided chunk sizes.
This is useful for processing large request bodies in chunks without loading everything into memory — for example, saving portions of a large body to multiple files.

Relates to #3113
Example usage:
chunk1 = await request.read(1024) # first 1KB
chunk2 = await request.read(1024) # next 1KB
chunk3 = await request.read(-1) # rest of body

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@Jagdish1115
Copy link
Author

Hi,

This is my first open source contribution, so I appreciate any feedback or guidance.
I've implemented the read(size) method on the Request class as discussed in #3113. The method reads up to size bytes from the request body at a time using an internal buffer, avoiding loading the entire body into memory at once.
Regarding the coverage failure — I noticed the main branch is already at 89% coverage before my changes. I've added tests for the main scenarios but I'm still working on fully covering line 259. Any guidance would be greatly appreciated.

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.

1 participant