Skip to content

Add Request.WithLimit #271

@gavv

Description

@gavv

Add new method Request.WithLimit that set's a limit for maximum number of bytes that can be retrieved from response body.

It can be helpful to interrupt early on abnormally large response (e.g. mistakenly trying to read infinite chunked response into memory), thus avoiding insane memory consumption by tests, swapping, etc.

Request.WithLimit should store the provided limit into a private field of Request. Later, in Request.retryRequest we should check if limit is set, and if so, pass this limit to bodyWrapper when we're wrapping response body.

Then, we should teach bodyWrapper to handle the limit. When the limit is set and bodyWrapper detected that it read more bytes than desired, it should abort read and return error that explains that limit is exceed and what is the limit.

Ideally error message should contain limit both in bytes and in human readable form, like "5 MB".

New method should have documentation comment with code example and two tests:

  • unit test for request (request_test.go)
  • end-to-end (blackbox) test (we can create new file e2e_limit_test.go)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requesthelp wantedContributions are welcome

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions