Commit Graph

149 Commits

Author SHA1 Message Date
Vladislav Sedov fa2b76590b fix double release of streamed client response body (#2211)
Clear the response body stream when the client streaming wrapper is closed directly via CloseWithError. This prevents ReleaseResponse from closing the same underlying requestStream again.
2026-06-07 10:11:17 +02:00
Erik Dubbelboer da69ed9d3f bug: body stream leak in compression methods when response is discarded (#2244) (#2276) 2026-06-06 11:26:48 +02:00
Erik Dubbelboer f36c900902 header: match net/http CL+TE handling (#2190)
Match net/http behavior when requests or responses contain both
Content-Length and Transfer-Encoding.

Parse and validate Content-Length even when Transfer-Encoding is present, so
invalid lengths are rejected. For valid Content-Length with chunked
Transfer-Encoding, keep chunked framing as authoritative. Also apply the same
precedence when RequestHeader.DisableSpecialHeader is used.
2026-04-28 04:33:01 +02:00
Erik Dubbelboer 0b4cede30f header: reject unsupported response Transfer-Encoding (#2192)
Reject HTTP/1.1 response Transfer-Encoding values unless they are a single
chunked header, matching net/http's strict transfer parser behavior.

This prevents arbitrary or compound response Transfer-Encoding values from
being silently normalized to chunked and avoids desync/body parsing ambiguity
when parsing upstream responses.
2026-04-28 04:28:05 +02:00
Erik Dubbelboer c497746f7d http: reject whitespace before chunk extensions (#2193)
Reject space and tab between the chunk-size and chunk-extension separator while
preserving net/http-compatible trailing OWS before CRLF.

This avoids parser divergence for chunk lines such as "3 ;ext\r\n" without
breaking the existing acceptance of padded chunk-size lines like "3 \r\n".
Add parser regression coverage for both accepted and rejected forms.
2026-04-28 04:27:54 +02:00
Erik Dubbelboer b8d29bee6e header: reject pre-colon whitespace in request headers (#2187)
Reject request header field names with whitespace immediately before the
colon instead of trimming them before special-header handling.

This prevents parser differentials for malformed framing and routing
headers such as Content-Length, Transfer-Encoding, and Host when a frontend
forwards raw invalid request headers.

Keep the existing response and trailer compatibility behavior unchanged, and
add regression coverage for both header-only parsing and full request body
reads.
2026-04-27 05:28:18 +02:00
Erik Dubbelboer 82254a7add Normalize framing header names with pre-colon whitespace 2026-03-28 07:08:16 +01:00
Erik Dubbelboer 611132707f Strict HTTP version validation and simplified first line parsing (#2167) 2026-03-28 04:31:32 +01:00
Erik Dubbelboer eb38f5fc14 HTTP1/1 requires exactly one Host header (#2164)
Bring our parser more in line with net/http.
2026-03-28 03:10:37 +01:00
Erik Dubbelboer 3c43293b0c Prevent chunk extension request smuggling (#2165) 2026-03-28 03:10:11 +01:00
Erik Dubbelboer f0d5d9a5cb Add WithLimit methods for uncompression (#2147)
* Add WithLimit methods for uncompression

The current uncompress methods don't enforce a memory limit and are
susceptible to things like zip bombs. This pull introduces new methods
so retain backwards compatibility. The old methods might be deprecated
in the future.

* Fix suggestion
2026-02-22 18:13:40 +01:00
Erik Dubbelboer c2b317d47d Go 1.26 and golangci-lint updates (#2146)
Keep Go 1.24 compatibility for now (by not using `wg.Go()`).
2026-02-21 10:28:39 +01:00
Erik Dubbelboer f18eb9ef0c Reject backslash absolute URIs and cache parse errors (#2075)
Keep our server behaviour the same as net/http.
2025-10-05 02:47:11 +02:00
Erik Dubbelboer f9d84d7c52 Rewrite header parsing to improve spec compliance (#2030)
This change updates header parsing to match the behavior of net/http more closely.

**Breaking change**: headers delimited by `\n` (instead of `\r\n`) are no longer supported.

Previously, fasthttp accepted `\n` as a delimiter, which is not spec compliant.
This made it difficult to correctly parse headers containing both `\n` and `\r\n`.
2025-08-12 15:49:35 +02:00
osxtest 1345f42ede Add support for streaming identity-encoded or unknown length response bodies (#2000) 2025-05-03 13:51:32 +09:00
Agustin Arce 0b74893830 feat (request): expose req timeout (#1878)
* feat (request): expose req timeout as string

* refactor (http): update return type of GetTimeOut

* docs (http): add doc to GetTimeOut
2024-10-05 15:49:40 +02:00
Erik Dubbelboer df8335f9ab A response without a body can't have trailers (#1825) 2024-08-20 23:10:04 +02:00
Max Denushev 57b9352ad1 fix: propagate body stream error to close function (#1743) (#1757)
* fix: propagate body stream error to close function (#1743)

* fix: http test

* fix: close body stream with error in encoding functions

* fix: lint

---------

Co-authored-by: Max Denushev <denushev@tochka.com>
2024-04-22 08:45:33 +02:00
Oleksandr Redko bdd459ab0e test: remove //nolint:govet comments (#1729) 2024-03-02 16:19:52 +01:00
Oleksandr Redko 3166afd835 Enable few gocritic checks; fix up issues (#1728) 2024-03-02 16:19:05 +01:00
Oleksandr Redko 190204cf1a Upgrade golangci-lint to v1.56.2; fix gocritic issues (#1722) 2024-02-21 05:51:28 +01:00
Erik Dubbelboer 3327266342 Follow RFCs 7230 and 9112 for HTTP versions (#1710)
Require that HTTP versions match the following pattern: HTTP/[0-9]\.[0-9]
2024-02-11 07:55:31 +01:00
Erik Dubbelboer a04cd8c39f Move Fuzz tests into their own file
This is required for https://github.com/google/oss-fuzz/pull/11453
2024-01-09 13:01:31 +01:00
nickajacks1 f0905a14d1 test: migrate remaining fuzzit tests to go 1.18 fuzzing (#1687) 2024-01-06 13:39:23 +08:00
Oleksandr Redko 28615eba55 Change empty string checks to be more idiomatic (#1684) 2024-01-04 15:05:38 +01:00
Oleksandr Redko 8ecfc989d9 Enable dupword, unconvert linters (#1658) 2023-11-12 16:42:39 +01:00
Oleksandr Redko 4ec5c5a774 docs: fix typos in comments and tests 2023-08-30 14:13:13 +02:00
Duncan Overbruck 6aea1e0d44 fix round2_32, split round2 tests because they depend on sizeof int at compile time (#1607) 2023-08-24 20:39:33 +02:00
Erik Dubbelboer 1c85d43dfe Fix round2
- don't limit it to 32 bits
- give it a proper name
- don't over-allocate too much
2023-07-08 12:40:36 +02:00
Oleksandr Redko ffdf59d04c Enable gofumpt linter; format code gofumpt -w . (#1576) 2023-06-13 15:18:59 +02:00
Erik Dubbelboer fa72f3cc39 Fix tests (#1552) 2023-05-07 14:32:14 +02:00
Oleksandr Redko 1dcf56222d test: refactor to use WriteString (#1546) 2023-04-28 17:39:58 +02:00
Oleksandr Redko 1aac29366c test: use ReplaceAll, remove unnecessary else (#1542) 2023-04-25 13:17:59 +02:00
Abe Saiovici d76662b46d Fixed transfer-encoding for empty chunked payload (#1536) 2023-04-12 22:51:30 +02:00
Anthony-Dong 6b958c2c22 support response body stream (#1414)
* feat: support response body stream

* style: add header interface

* Update http.go

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>

* feat: support request、response、client stream

* fix: close reader bug

---------

Co-authored-by: fanhaodong.516 <fanhaodong.516@bytedance.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-04-05 18:56:31 +02:00
Oleksandr Redko 0be5a4150c test: simplify bytes.Buffer declaration (#1523) 2023-03-18 14:40:25 +01:00
Oleksandr Redko 934f04e330 Refactor golangci-lint config and remove redundant nolints (#1486)
* Refactor golangci-lint config

- Use golangci-lint-action for GitHub workflow.
- Add additional golangci-lint run options.
- Remove unused nolint directives.

* Revert exclude-use-default option
2023-02-11 15:35:15 +08:00
Oleksandr Redko c0c5f9cd38 doc,test: correct typos (#1484) 2023-02-09 09:29:28 +01:00
kinggo e87f84c51a fix: CopyTo doesn't copy bodyraw deeply (#1471) 2023-01-14 10:44:11 +08:00
nick9822 c88dd5dc02 fix form empty field error when used with pipe (#1417)
Co-authored-by: root <nikesh.tawde@digitalairtech.com>
2022-11-03 21:24:53 +01:00
byene0923 eca86de6f6 fix: (#1410)
1. the length of trailer key should > 0
2. fix http_test words typo
2022-10-29 18:32:18 +02:00
byene0923 e2141372b6 fix: ignore body should not set content-length of streaming (#1406)
* fix: ignore body should not set content-length of streaming https://github.com/valyala/fasthttp/pull/1022

* fix: add commit
2022-10-29 18:32:08 +02:00
Aoang a696949f6c Deprecate Go 1.15 (#1379)
* Dropping support for 1.15.

* Replaces Go 1.16 Deprecated functions

* Update test build flag

* Fix import sort and comment

* Update github.com/klauspost/compress to v1.15.9

https://github.com/klauspost/compress improved performance and changed Minimum version is 1.16, this should be the final supported release for Go 1.16 (https://github.com/klauspost/compress/commit/6d0019a95afa3221f7522d1f2eed0033b5e79470) .
2022-09-15 22:28:25 +03:00
mathew 42f83c60cf Prevent overflow and panic on large HTTP responses (#1351) 2022-07-29 18:58:52 +02:00
Sergey Ponomarev 35aca7b6df BodyDecoded() for request and responses (#1308)
* header.go ContentEncoding() getter and setters

For Response the CE header is stored into a separate field because compressed responses are often used.
But for the Request let's just peek and store it from headers map

* http.go: New BodyUncompressed() method for request and responses

The new method returns a body and uncompress if it's gzipped
2022-06-06 08:59:16 +02:00
Sergey Ponomarev c9f43eaa1b Response.ContentEncoding(): store as field and avoid using Header.SetCanonical() (#1311)
* Response.ContentEncoding(): store as field

The CE is not so often used for plain APIs responses and even not so often used for static files and on the fly compression.
But still it should be checked each time.
Also having a dedicated field getter and setter simplifies code

* header.go Use shorter Response.setNonSpecial() and Request.setNonSpecial() methods instead of SetCanonical()

The change should improve performance because the setSpecialHeader() call is omitted.
As a downside on adding a new basic header field all putHeader() must be replaced with a direct getter and setter.
2022-06-05 15:47:59 +02:00
Erik Dubbelboer 7a5afddf5b Use %v for errors and %q for strings (#1262)
Mostly in tests.
2022-04-01 18:11:16 +02:00
Erik Dubbelboer 1116d034d5 Fix panic while reading invalid trailers 2022-03-01 20:50:12 +01:00
Tolyar c727b9981b Release UseHostHeader in ReleaseRequest() (#1185)
* Fix UseHostHeader for DoTimeout + tests

* Release UseHostHeader in ReleaseRequest() + tests
2021-12-28 19:26:04 +08:00
Tolyar 6c0518b89a Fix UseHostHeader for DoTimeout + tests (#1184) 2021-12-26 21:08:23 +08:00