Commit Graph

220 Commits

Author SHA1 Message Date
Oleksandr Redko 7e1fb71854 Enable perfsprint linter; fix up lint issues (#1727) 2024-03-02 16:21:23 +01:00
Oleksandr Redko 3166afd835 Enable few gocritic checks; fix up issues (#1728) 2024-03-02 16:19:05 +01:00
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
nickajacks1 2accefa5cb refactor: move manually created tchar table to bytesconv_table_gen (#1689) 2024-01-07 08:27:45 +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 9d6b470260 chore: Add missing dots at the end of comments (#1677) 2023-12-13 13:56:24 +08:00
xiluoxi 497922a21e reset request disableSpecialHeader (#1626) 2023-09-22 14:21:18 +02:00
Oleksandr Redko 9aa666e814 Enable gocritic linter; fix lint issues (#1612) 2023-08-29 20:08:37 +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
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
cui fliter ac631aa4eb fix functiom name (#1505)
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-03-03 17:43:44 +01:00
Oleksandr Redko e15a810a98 docs: fix grammar issues and typos in comments (#1492) 2023-02-13 10:43:44 +08: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
Erik Dubbelboer dbf457ee66 Revert "feat: support mulit/range (#1398)" (#1446)
This reverts commit a468a7dd37.
2022-11-28 11:52:30 +01:00
kinggo 7b3bf58850 style: modify typo and remove repeated type conversions (#1437) 2022-11-18 08:13:18 +02: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
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
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
Aoang ea6052464e Add Go 1.19 Support (#1355)
* Update Go Version to Go1.19.x And add cache

* Fix CI Line endings

* Update test CI Go Version to Go1.19.x And add cache

* Update Gosec Security Scanner CI to securego/gosec@v2.12.0

* Format comment

Go 1.19 adds support for links, lists, and clearer headings in doc comments. As part of this change, gofmt now reformats doc comments to make their rendered meaning clearer. See “Go Doc Comments” for syntax details and descriptions of common mistakes now highlighted by gofmt. As another part of this change, the new package go/doc/comment provides parsing and reformatting of doc comments as well as support for rendering them to HTML, Markdown, and text.

ref: https://tip.golang.org/doc/go1.19
ref: https://tip.golang.org/doc/comment

* Fix doc structure
2022-08-14 11:31:57 +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 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 66cd5022fd header.go Referer() optimize (#1313)
* args.go GetBool(): use switch with string casting

This should be optimized by Go compiler itself so the b2s() call is not needed.

It was previously done by this but changed in
1e7885eb56

* header.go Referer() optimize

Use direct peekArgBytes() instead of PeekBytes() that will check for special headers

* header_timing_test.go BenchmarkRequestHeaderPeekBytesSpecialHeader

The old BenchmarkRequestHeaderPeekBytesCanonical and BenchmarkRequestHeaderPeekBytesNonCanonical are in fact just measured the header normalization.
But it's anyway is benchmarked separately.
Results was almost the same: 1.5 ns/op.

Instead, let's reuse the benches to find a difference between peeking of special (Host, CT) and custom headers.
2022-06-06 08:46:49 +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
Jack.Ju ad8a07a86e RequestHeader support set no default ContentType (#1218) 2022-02-16 15:52:18 +01:00
Erik Dubbelboer 7eeb00e1cc Make tests less flaky (#1189) 2022-01-10 05:15:30 +01:00
Erik Dubbelboer e9db537178 Use %w to wrap errors (#1175) 2021-12-13 09:41:34 +01:00
Erik Dubbelboer 7db0597e75 Fix bad request trailer panic 2021-12-13 09:01:16 +01:00
Erik Dubbelboer 4aadf9a85e Fix parseTrailer panic 2021-12-06 14:48:36 +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
tyltr 6006c8761d chore (#1137) 2021-10-30 15:58:20 +02: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
tyltr fe7d90ed50 remove redundant code (#1127) 2021-10-19 12:47:55 +02:00
Erik Dubbelboer ffab77a59d Improve return value reusability documentation 2021-10-01 13:38:31 +02:00
Erik Dubbelboer 46d92356a8 Check go fmt during lint (#1097) 2021-09-10 18:49:45 +02:00
Kyle Unverferth 713da4e33f Adding new compressible prefixes (#1092)
* Adding "image/svg" as compressible prefix

* Adding additional compressible prefixes from https://support.cloudflare.com/hc/en-us/articles/200168396-What-will-Cloudflare-compress-
2021-09-07 10:03:41 +02:00
tyltr f0a21893b9 feat: improve IsMethod (#1088)
* feat: improve bytesEqual

* benchmark

* nolint:unused

* remove unused  code

* Update client.go

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

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2021-09-06 12:06:21 +02:00
Erik Dubbelboer f6560bebb2 Flush buffered responses if we have to wait for the next request (#1050)
* Flush buffered responses if we have to wait for the next request

Don't wait for the next request as this can take some time, instead
flush the outstanding responses already.

Fixes #1043

* Only peek 1 byte

Make sure old clients that send bogus \r\n still work.
See: https://github.com/golang/go/commit/bf5e19fbaf02b1b25fbe50c27ec301fe830a28d0
2021-06-28 17:38:39 +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
Darío 1b61ca2e36 Added Protocol() as a replacement of hardcoded strHTTP11 (#969)
* Added Protocol() as a replacement of hardcoded strHTTP11

* Applied review changes

* Modify h.proto in parseFirstLine
2021-02-16 21:53:40 +01:00