* add byte to string unsafe conversion to fasthttpadaptor ConvertRequest method()
* add nosec comment line
* Update fasthttpadaptor/request.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* move unsafe package import next to std packages
* fix lint error in test
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* 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
* use timeout insteadof read/writetimeout when timeout lower than read/writetimeout
* use deadtime; fix test timeout;
Co-authored-by: 徐焱 <xuyan4@staff.sina.com.cn>
When calling closeIdleConns() also close new connections that haven't
received any data within 5 seconds.
Some applications open new connections but don't send anything and keep
them as keep-alive for potential future requests. We don't want to
keeping hanging on these when shutting down a server.
* 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
* 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.
* 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.
* server.go Make code more clear
Inline isHTTP11 var.
Use direct Header.SetConnectionClose() and Header.ConnectionClose()
* server.go Use direct SetConnectionClose()
The SetCanonical(strConnection, strClose) call internally will anyway call SetConnectionClose().
The "Connection: close" will be printed in the ResponseHeader.AppendBytes()
* server.go Simplify connectionClose evaluation
The conn limit check merged into connectionClose evaluation.
This improves performance for most cases:
1. If the connectionClose already true then the conn limit check won't be performed.
2. The SetConnectionClose() was duplicated
3. First check conn limit and only then check for resp.connClose because most users don't close conns manually.
4. We may optimize more: If the resp.connClose = true then SetConnectionClose() not needed but as mentioned above this is a rare case.
* support adding/removing clients from LBClient
* add/remove BalancingClient to be more flexible
* use RwMutex, lock for get
* lock mutex for init
* defer unlock for possible panic
* fix removing client
* fix filtering of slice
* fix removing references to removed items
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
We have a RequestCtx pool per server so we only need to set it once.
This fixes a race codition where acquireCtx would assign .s while
.Done() is reading it. Even though acquireCtx would always set it to the
same, already assigned, value it would still trigger the race detector.
Fixes: https://github.com/valyala/fasthttp/issues/1261
The bytesconv 32-bit tests fail on s390x, because it is a 64-bit
architecture. Add the appropriate build flags so that 32-bit tests do
not run on this architecture.
* Read response when client closes connection #1232
* Fix edge case were client responds with invalid header
* Follow linter suggestions for tests
* Changes after review
* Reafactor error check after review
* Handle connection reset on windows
* Remove format string from test where not needed
* Run connection reset tests not on Windows
RequestCtx's are reused in a server specific pool, so no need to reset
it. This fixes a use after reset but when RequestCtx is use as context.
Fixes#1205
* Fix windows tests
Just ignore /../ tests on windows until we have proper suppor.
* Remove useless test code
This code was basically just testing if tcp works. To test if
SO_REUSEPORT works we only have to try to listen on the same addr:port
twice.
* Fix test
* feature: add request and response body size limit, it prevents the large body from slowly stretching the memory of the entire service
* fix: http.go fmt
* refact: optimize code naming
* Update http.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* Update http.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* Update http.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* Update http.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
* Update http.go
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>