Commit Graph

122 Commits

Author SHA1 Message Date
Erik Dubbelboer bce576699a Prevent request smuggling (#1719)
* Prevent request smuggling

Prevent request smuggling when fasthttp is behind a reverse proxy that
might interprets headers differently by being stricter. Should also
prevent request smuggling when fasthttp is used as the reverse proxy.

* Make header value comparison case-insensitive
2024-02-11 08:08:56 +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
Oleksandr Redko 28615eba55 Change empty string checks to be more idiomatic (#1684) 2024-01-04 15:05:38 +01:00
nickajacks1 868ee455d5 feat: add function to parse HTTP header parameters (#1685)
* feat: add function to parse HTTP header parameters

The implementation is based on RFC-9110 5.6.6.

* test: add fuzz for VisitHeaderParams
2024-01-02 09:43:40 +01:00
Oleksandr Redko 4ec5c5a774 docs: fix typos in comments and tests 2023-08-30 14:13:13 +02:00
Oleksandr Redko 9aa666e814 Enable gocritic linter; fix lint issues (#1612) 2023-08-29 20:08:37 +02:00
Oleksandr Redko 064124ec85 Avoid nolint:errcheck in header tests (#1589) 2023-07-06 09:11:45 +02:00
AutumnSun 0d0bbfee5a Auto add 'Vary' header after compression (#1585)
* Auto add 'Vary' header after compression

Add config `SetAddVaryHeaderForCompression` to enable
'Vary: Accept-Encoding' header when compression is used.

* feat: always set the Vary header

* create and use `ResponseHeader.AddVaryBytes`

* not export 'AddVaryBytes'
2023-07-02 12:40:26 +02:00
Oleksandr Redko ffdf59d04c Enable gofumpt linter; format code gofumpt -w . (#1576) 2023-06-13 15:18:59 +02:00
Anthony Ter-Saakov b79233fac2 add DisableSpecialHeaders option (#1573)
* add DisableSpecialHeaders option

* polishing up disableSpecialHeader option

* forgot to uncomment

* fix silly mistakes

* dont parse special headers
2023-06-12 21:49:52 +02:00
kinggo 43cc4870e6 fix: add noDefaultContentType copy (#1538) 2023-04-14 10:38:32 +02:00
Oleksandr Redko 498a814fbf test: fix typos in function, error message, comment (#1512) 2023-03-06 16:55:21 +01:00
Oleksandr Redko b79a03aaf9 test: close response body (#1496) 2023-02-15 11:54:23 +01:00
Oleksandr Redko 5147cecec7 docs: replace links to golang.org with go.dev (#1489)
- Replace https://godoc.org with https://pkg.go.dev.
- Replace https://golang.org with https://go.dev.
- Replace https://golang.org/pkg with https://pkg.go.dev.
- Replace https://blog.golang.org with https://go.dev/blog.
- Use https://pkg.go.dev/golang.org/x/net/http2  instead of non-existing https://http2.golang.org/.
- Remove trailing slashes.
2023-02-11 19:59:44 +08:00
Oleksandr Redko c0c5f9cd38 doc,test: correct typos (#1484) 2023-02-09 09:29:28 +01:00
Erik Dubbelboer dbf457ee66 Revert "feat: support mulit/range (#1398)" (#1446)
This reverts commit a468a7dd37.
2022-11-28 11:52:30 +01:00
byene0923 a468a7dd37 feat: support mulit/range (#1398)
* feat: support mulit/range

* fix:
1. lint code
2. add SetByteRanges method

* fix: reduce the test number of testFSSingleByteRange
2022-10-30 09:48:46 +01:00
kinggo 3963a79a64 feat: add PeekKeys and PeekTrailerKeys (#1405)
* feat: add PeekKeys and PeekTrailerKeys

* Improve warning

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2022-10-29 18:57:40 +02:00
kinggo 128e9b35c4 optimize: adjust the behavior of PeekAll based on VisitAll (#1403) 2022-10-22 12:04:46 +02:00
kinggo 2c8ce3b40e feat: add header.PeekAll (#1394) 2022-10-15 15:47:53 +02:00
Erik Dubbelboer a5f448fc97 Improve Client timeout (#1346)
Don't run requests in a separate Goroutine anymore. Instead use proper
conn deadlines to enforce timeouts.

- Also contains some linting fixes.
2022-07-29 19:03:15 +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
Jack.Ju ad8a07a86e RequestHeader support set no default ContentType (#1218) 2022-02-16 15:52:18 +01:00
ichx da7ff7a208 Add trailer support (#1165)
* Add trailer support

* fix issue and add documentation

* remove redundant code

* add error return for add/set trailer method

* fix lint error

* fix bad trailer error return issue and update bad content-length error

* update errNonNumericChars

* update errNonNumericChars

* fix issue about error and fix typo
2021-12-05 14:11:51 +01:00
Shivansh Vij 2ca01c7efb fix: Status Line parsing and writing (#1135)
* Adding zero-allocation uint64 to byte slice conversion and fixing the ResponseHeader.SetStatusLine function call signature

* Removing unnecessary i2b function

* Fixing various bugs

* Adding test cases

* Commenting AppendStatusLine

* Update status.go

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

* Update header.go

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

* Cleaning up references to strHTTP11, using formatStatusLine for invalidStatusLine, and making `appendStatusLine` an unexported function

Issue: https://github.com/valyala/fasthttp/issues/1132

* Fixing merge conflicts

Issue: https://github.com/valyala/fasthttp/issues/1132

* Replacing []byte{} with nil in some test cases

Issue: https://github.com/valyala/fasthttp/issues/1132

* Cleaning up parsing first line, and improving StatusMessage function

Issue: https://github.com/valyala/fasthttp/issues/1132

* Fixing as per PR

* Update header.go

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

* Update header.go

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

* Fixing as per requested changes

* Update header_test.go

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

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2021-11-08 09:44:02 +01:00
Valentin Paz Marcolla 556aa814e4 feat: ability to edit status messages (#1126)
* SetStatusMessage

* Docstring

* statusLine in header

* Use statusLine as []byte + ResponseHeader parsing

* status line getter
2021-10-22 17:53:35 +02:00
Kazumasa Takenaka (Bamboo) 9466cd7657 fix typo: occured -> occurred (#1061) 2021-07-17 17:51:59 +02:00
Erik Dubbelboer 9f2c63676d Lower go test time 2021-06-18 14:57:18 +02:00
Erik Dubbelboer 6233fbc08e Fix header .Add functions (#1036)
These functions should take the headers that are handled differently
into account.
2021-06-01 10:52:35 +02:00
Erik Dubbelboer 5bb5cfc9ca Remove unused peekRawHeader 2021-05-26 09:09:50 +02:00
MoreFreeze ffa0cabed8 Use proper content-type when it is not present (#1023)
Co-authored-by: liuchenxing <liuchenxing@bytedance.com>
2021-05-17 09:20:18 +02:00
Daniel Firsht 2a6f7db5bb Adding support for securing error logs (#1001)
Co-authored-by: Daniel Firsht <firsht@amazon.com>
2021-03-26 10:46:57 +01:00
AlphaBaby a88030b8fb fix gracefilly shutdown bug, issue #958 (#960)
* fix gracefilly shutdown bug, issue #958

* fix golangci-lint

* add option: CloseOnShutdown into Sever

* Update server.go

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

* Update server.go

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

Co-authored-by: fujianhao3 <fujianhao3@jd.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2021-02-07 21:13:36 +01:00
sky cc8ba4b5a3 Add a api DisableNoDefaultContentType to disable add default content type. (#859)
* Add api DisableNoDefaultContentType to disable add default contentype if no Content-Type header.

* Update test case.

* Update api name.

* Update header.go

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

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2020-08-07 17:38:59 +02:00
Erik Dubbelboer bcaa594b41 Remove unused raw header code 2020-05-31 15:49:37 +02:00
phuslu b71c8c513c Add support for NoDefaultDate option that excludes the sending of the Date header (#758) 2020-03-13 11:00:44 +01:00
Erik Dubbelboer 415e5fc531 Fix panic in header parser 2019-12-14 22:20:09 +01:00
Erik Dubbelboer fd55658938 Improve multiline header parsing (#708)
- Replace tabs with spaces at line starts to match net/http
- Don't allow multi line header names. See: https://github.com/golang/go/issues/34702
2019-12-14 10:58:06 +01:00
tedli 6a8a72ac18 add extra checking of header buffer, to support multi line header value (#123) (#688) 2019-12-14 09:45:35 +01:00
Erik Dubbelboer 39dd1045bb Allow a body for GET requests (#703)
This means we can't skip parsing headers for GET requests anymore. This
can be seen as good as it also allows us to reject malformed GET
requests, something we didn't do before this. Performance also isn't
affect much:

benchmark                                            old ns/op     new ns/op     delta
BenchmarkClientGetEndToEnd1Inmemory-16               640           641           +0.16%
BenchmarkClientGetEndToEnd10Inmemory-16              713           710           -0.42%
BenchmarkClientGetEndToEnd100Inmemory-16             732           749           +2.32%
BenchmarkClientGetEndToEnd1000Inmemory-16            759           774           +1.98%
BenchmarkClientGetEndToEnd10KInmemory-16             785           808           +2.93%
BenchmarkNetHTTPClientGetEndToEnd1Inmemory-16        5045          4954          -1.80%
BenchmarkNetHTTPClientGetEndToEnd10Inmemory-16       5806          6225          +7.22%
BenchmarkNetHTTPClientGetEndToEnd100Inmemory-16      7877          7998          +1.54%
BenchmarkNetHTTPClientGetEndToEnd1000Inmemory-16     16603         16559         -0.27%
2019-12-01 09:44:11 +01:00
Erik Dubbelboer 32793db72d Run golangci-lint using a Github Action 2019-11-16 18:09:28 +01:00
ZhangYunHao 707b1c1917 Format errors (#679)
* format errors

* Server is a type name

* Fix typo
2019-10-23 20:12:59 +08:00
Erik Dubbelboer c3d82ca3a4 Speed up testing by running tests in parallel 2019-10-16 10:20:13 +02:00
Erik Dubbelboer 9dbe5fc77c Don't allow spaces in request header keys
See: https://github.com/golang/go/commit/6e6f4aaf70c8b1cc81e65a26332aa9409de03ad8

Reject any non GET or HEAD requests with a 400.

We can't reject GET or HEAD requests with bad headers as we delay
parsing of these headers until the user asks for one. So in this case we
just ignore the header and don't return a value for it.
2019-10-16 10:20:13 +02:00
Ciprian Dorin Craciun 85217e0d5e Correctly handle NoDefaultContentType without setting an Content-Type value (#628)
If `NoDefaultContentType` is set, but no actual `Content-Type` header is set, do not send the wrong `Content-Type: ` header
2019-08-13 11:53:03 +02:00
Maxim Lebedev d3715c361c Used Headers constants instead raw strings 2019-05-28 18:04:24 +03:00
Maxim Lebedev f544170d63 Added methods constants (#567)
*  Added methods constants

* 👌 Fixed methods comment due to review changes
2019-05-06 17:54:49 +02:00
xuecai ed3793a1e1 add tests for copyto (#545)
* add tests for copyto
* add HeaderCopy Test reflect.DeepEqual
2019-02-17 10:11:45 +00:00