Commit Graph

120 Commits

Author SHA1 Message Date
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
Tolyar 4517204499 Allow to set Host header for Client (#1169)
* Allow to set Host header for Client

* Allow to change Host header without tests violation

* Rename AllowToChangeHostHeader and add tests.

* Allow to use empty uri.Host() when req.Header.Host() does not empty
2021-12-17 06:26:17 +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
Sergey Ponomarev 8febad0797 http.go: Request.SetURI() (Fix #1141) (#1148)
Currently, the only way to set URI for a request is to call SetRequestURI(string).
Then when a request performed the string will be parsed into a fasthttp.URI struct.
If there are many requests with the same URI then we'll waste CPU for a parsing of the same URI string.
With the new SetURI(*URI) method we can once parse a URI string into a fasthttp.URI struct and then reuse it for many requests.
Unfortunately the URI will be copied because may be modified inside the request.
But anyway this will be more lightweight than parsing.
2021-11-08 13:09:35 +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
Erik Dubbelboer 9f2c63676d Lower go test time 2021-06-18 14:57:18 +02:00
MoreFreeze 097fa05a69 Fix ignoreBody still set content length (#1022)
* Fix ignore body should not set content-length

* Add TestRequestReadNoBody

Co-authored-by: liuchenxing <liuchenxing@bytedance.com>
2021-05-14 10:08:51 +02:00
Vladimir Shteinman 0cd7349686 ImmediateHeaderFlush when no body (#995) 2021-03-15 18:10:51 +01:00
Erik Dubbelboer 70e00dc4f3 Ignore empty Transfer-Encoding headers
Don't default to chunked. If we have a Content-Length header we have a fixed body.
2021-01-06 19:18:12 +01:00
Kirill Danshin d0dfbd4494 fix issue #875 (#909)
* 🐞 panic in fs.go #824

* fix issue #875

Signed-off-by: Kirill Danshin <kirill@danshin.pro>

* improve issue 875

Co-authored-by: Fenny <fenny@gofiber.io>

* Update header.go

* Update header.go

Co-authored-by: Kirill Danshin <kirill@danshin.pro>

* remove foldReplacer

* Improve removeNewLines

Start replacing at the first character found, use bytes.Indexbyte to
make the function signature more logical. Both bytes.indexByte and
strings.IndexByte use exactly the same code:
https://github.com/golang/go/blob/0c703b37dffe74d3fffc04347884bb0ee2fba5b3/src/internal/bytealg/indexbyte_amd64.s#L8-L20

Co-authored-by: wernerr <rene.werner@verivox.com>
Co-authored-by: wernerr <rene@gofiber.io>
Co-authored-by: Fenny <fenny@gofiber.io>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2020-12-09 16:59:57 +01:00
Erik Dubbelboer ce7b94fee9 Add Request.SetBodyRaw
Fixes https://github.com/valyala/fasthttp/issues/891
2020-11-02 22:22:01 +01:00
Erik Dubbelboer 34a61fe63f Update linting (#851) 2020-07-17 14:22:28 +02:00
Markmerc db18810c87 Add configuration to not pre-parse multipart form data (#778)
Co-authored-by: Mercurio <mmmercur@amazon.com>
2020-04-14 18:17:57 +02:00
Erik Dubbelboer 76b74e34c2 Don't send the fragment/hash/# part of a URL to the server
Fixes https://github.com/valyala/fasthttp/issues/748
2020-02-28 18:56:02 +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
Vladimir Shteinman 70223a183c Recover from panic in body write (#687)
* Recover from panic in body stream write

* CR + Add tests
2019-11-06 14:35:52 +01:00
Erik Dubbelboer c3d82ca3a4 Speed up testing by running tests in parallel 2019-10-16 10:20:13 +02:00
Maxim Lebedev d3715c361c Used Headers constants instead raw strings 2019-05-28 18:04:24 +03:00
Vladimir Shteinman 74ad0f8e9b Export struct var and add specs 2019-05-22 23:23:02 +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
Ciprian Dorin Craciun 733a6505a9 Support huge read-only []byte response bodies (#477)
* Add `Response.SetBodyRaw` method that serves a `[]byte` slice without touching it  (as an alternative to `SetBody`)
* Update various response related functions that are impacted after the incoduction of `Response.bodyRaw`
* Add a few test-cases in relation to `Response.SetBodyRaw`
2019-02-24 08:32:54 +00: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
xuecai 10b98c2cdf add conn's address info in Response (#537)
* reset commit
* fix response copy bug; add tests;
2019-02-16 10:50:14 +00:00
Shulhan 9574c37fb8 Various changes regarding code readibility (#523)
* all: use sort.Strings when applicable

Basically, sort.Strings is the shortcut of Sort(StringSlice(a)) but its
more readable.

* all: replace string(bytes.Buffer.Bytes()) with bytes.Buffer.String()

Although its only occured on test files, it may be worth to simplified it.

* http_test: simplify strings.Index with strings.Contains

Both have the same O(n), but strings.Contains more readable on
if-condition.

* args: simplify if-condition check on boolean value

* all: simplify variable initialization

If we assign the variable after declaring it, we can simplify it using
":=" operator or "= value".
The reader can still known the type of variable from the struct name or
variable type before assignment operator.
2019-02-02 11:13:33 +00:00
Erik Dubbelboer 192515395f Add Client.NoDefaultUserAgentHeader 2018-11-01 12:44:17 +08:00