mirror of
https://github.com/aykhans/sarin.git
synced 2026-11-30 20:46:17 +00:00
fix(script): enforce script body limits without streaming
Streaming accepted a chunked body cut at a chunk boundary as complete, so the limit now comes from the client that reads the body, picked per requested size. Script requests keep their own default, maxBodySize accepts sizes like 10MiB, and files sarin downloads for itself are capped at 64MiB.
This commit is contained in:
16 files changed
+222
-173
No files matched your search
@@ -179,7 +179,7 @@ The value is a whole number of bytes, with or without a unit: `B`, `KB`, `MB`, `
|
||||
|
||||
A server can declare a `Content-Length` far larger than it sends, and the body is allocated from that declared length, so without a limit a single response can exhaust memory. A response above the limit fails with `body size exceeds the given limit` and is counted like any other error.
|
||||
|
||||
The limit applies per response in flight, so the worst case is roughly the limit times the concurrency. It also applies to the requests scripts make, unless the script passes its own `maxBodySize` (see [HTTP Requests in Scripts](#http-requests-in-scripts)).
|
||||
The limit applies per response in flight, so the worst case is roughly the limit times the concurrency. Requests made by scripts have their own limit, see [HTTP Requests in Scripts](#http-requests-in-scripts).
|
||||
|
||||
## Concurrency
|
||||
|
||||
@@ -596,7 +596,7 @@ http(url, opts)
|
||||
| `timeout` | duration string (`"500ms"`) | `30s` | Request timeout (the `timeout` config does not apply), applied to each hop when redirects are followed |
|
||||
| `insecure` | boolean | `false` | Skip TLS verification (the `insecure` config does not apply) |
|
||||
| `maxRedirects` | number | `0` | How many redirects to follow, `0` follows none, maximum 100 |
|
||||
| `maxBodySize` | number | - | Largest response body to accept in bytes, maximum 1099511627776 |
|
||||
| `maxBodySize` | number or size (`"10MiB"`) | `10MiB` | Largest response body to accept (the max response body config does not apply), maximum `1TiB` |
|
||||
|
||||
Unknown options and values of the wrong type raise an error.
|
||||
|
||||
@@ -619,7 +619,7 @@ In Lua, call the helpers as `res:header("name")` or `res.header("name")`.
|
||||
- **Same proxy:** when proxies are configured, a script's requests go through the same proxy as the main request they belong to.
|
||||
- **Status codes:** non-2xx responses are returned normally; check `status` in the script.
|
||||
- **Errors:** network failures and timeouts raise a script error. The main request is not sent and the error is counted in the results. Scripts can catch it with `pcall` (Lua) or `try`/`catch` (JavaScript).
|
||||
- **Response bodies:** without `maxBodySize` the [Max Response Body](#max-response-body) config applies, as it does to the main request. With `maxBodySize` the body is read as it arrives, so a `Content-Length` the server never sends costs nothing, the limit is exact, and it may be larger than the config. Passing the limit raises an error instead of truncating the body.
|
||||
- **Response bodies:** script requests carry their own limit, like their own timeout, so the max response body config does not apply to them. A body above `maxBodySize` raises an error instead of being truncated, and a body whose declared `Content-Length` is already above it is refused before it is read.
|
||||
- **Only inside `transform`:** `http` works anywhere while `transform` runs, including in helper functions it calls. Calling it at the top level of a script raises an error, because that code also runs during config validation and when each worker starts.
|
||||
- **Dry run:** script requests are still sent in dry-run mode.
|
||||
- **Not measured:** script requests are not included in the results.
|
||||
|
||||
Reference in new issue
Block a user