Commit Graph

1502 Commits

Author SHA1 Message Date
pj d404f2db91 make RequestCtx's userdata accept keys that are of type: interface{} (#1387)
Co-authored-by: rocketlaunchr-cto <rocketlaunchr.cloud@gmail.com>
2022-10-06 16:25:32 +02:00
kinggo bcf7e8e944 test: merge test in adaptor_test.go (#1381)
* test: merge test in adaptor_test.go

* Fix lint

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2022-09-18 09:20:03 +02:00
Craig O'Donnell 31fdc796f4 resolve CVE-2022-27664 (#1377) 2022-09-15 23:02:06 +02:00
Emre Savcı 40eec0b706 byte to string unsafe conversion in fasthttpadaptor ConvertRequest method (#1375)
* 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>
2022-09-15 23:15:26 +03: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
Erik Dubbelboer 2f1e949d91 Improve isTLSAlready check
All conn implementations having a Handshake() error method are now seen
as a TLS conn and aren't wrapped in another tls.Client.
v1.40.0
2022-09-03 11:02:32 +02:00
tyltr 404c8a8968 Chore (#1365)
* chore-1

* chore2
2022-08-29 07:51:37 +02:00
Erik Dubbelboer 79ccfff72b Don't use tls ClientSessionCache
net/http doesn't use it either. Some servers have issues with this
preventing fasthttp from working:

https://github.com/valyala/fasthttp/issues/1364
https://github.com/valyala/fasthttp/issues/1296
https://github.com/valyala/fasthttp/issues/1335
https://github.com/valyala/fasthttp/issues/984

Also removed code that benchmarks crypto/tls as that has nothing to do
with fasthttp.
2022-08-28 10:13:03 +02:00
Erik Dubbelboer 28bec71c96 Fix "use of closed network connection" error check
This was refactored out incorrectly in a previous change.
2022-08-26 14:15:21 +02:00
Geralt X Li 3b147b7fe4 Fix(server): reset maxRequestBodySize to the server's config (#1360)
* fix(server): reset maxRequestBodySize to the server's config when HeaderReceived is set

* fix(server): reset writeTimeout
2022-08-23 16:44:59 +02:00
Qing Moy af94725d11 Reduce slice growth in adaptor (#1356) 2022-08-16 10:28:42 +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
v1.39.0
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
mathew 42f83c60cf Prevent overflow and panic on large HTTP responses (#1351) 2022-07-29 18:58:52 +02:00
mojatter f3513ccc59 Introduce FS.CompressRoot (#1331)
* Introduce FS.CompressRoot

* Avoid duplicated filepath.FromSlash

* Introduce filePathToCompressed

* Revert openIndexFile manually

* Join root and path, and then calls filepath.FromSlash
2022-07-10 10:07:18 +02:00
fare83 c94be05897 use timeout insteadof read/writetimeout when timeout lower than read/… (#1336)
* use timeout insteadof read/writetimeout when timeout lower than read/writetimeout

* use deadtime; fix test timeout;

Co-authored-by: 徐焱 <xuyan4@staff.sina.com.cn>
2022-07-06 14:03:50 +02:00
Erik Dubbelboer b23c5e9083 Close new connections after 5s in closeIdleConns
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.
2022-06-28 11:04:21 +02:00
kayos 5b0cbf29b4 Fix apparent documentation typo (#1330) 2022-06-28 09:54:03 +02:00
zhangyongding 16d30c474c Support AIX SO_REUSEADDR and SO_REUSEPORT (#1328)
* Update reuseport.go

* Create reuseport_aix.go
v1.38.0
2022-06-26 10:08:47 +02:00
Y.Horie bc24f9d683 Consolidate TCPKeepalive in server.Serve (#1320) (#1324) 2022-06-20 21:42:05 +02:00
Thearas 8a320890c0 Add ConnPoolStrategy field to client (#1317) 2022-06-07 09:21:26 +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
Sergey Ponomarev de188244b4 Optimize server connection close logic (#1310)
* 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.
2022-06-05 13:05:46 +02:00
RW 66bc61ee64 Add an option to allow empty root in the fsHandler (#1299)
* Add an option to allow empty root in the fsHandler

this is necessary to restore the capabilities before the commit https://github.com/valyala/fasthttp/commit/c7576cc10cabfc9c993317a2d3f8355497bea156
and to allow further functionality to be docked from the outside which is not affected by setting the root dir afterwards

https://github.com/gofiber/fiber/pull/1882#issuecomment-1120832500

* Add an option to allow empty root in the fsHandler

this is necessary to restore the capabilities before the commit https://github.com/valyala/fasthttp/commit/c7576cc10cabfc9c993317a2d3f8355497bea156
and to allow further functionality to be docked from the outside which is not affected by setting the root dir afterwards

https://github.com/gofiber/fiber/pull/1882#issuecomment-1120832500

* Update fs.go

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

* Update fs.go

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

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
v1.37.0
2022-05-16 12:33:47 +02:00
Erik Dubbelboer 9961079196 Fix userdata re-use after Remove
See also: https://github.com/valyala/fasthttp/pull/1298
2022-05-11 16:11:18 +02:00
Erik Dubbelboer 7cc6f4c513 Fix DoTimeout Streaming body bug v1.36.0 2022-04-26 00:45:51 +02:00
tyltr 9a0b4d088c optimize (#1275)
* opotimize

* lint

* without min

* less comparisons
2022-04-24 17:35:14 +02:00
tyltr e3d25122db optimize (#1272) 2022-04-19 18:39:32 +02:00
Mikhail Faraponov b40b5a4ca3 Update tlsClientHandshake (#1263)
* Update tlsClientHandshake

* Update client.go

* Update client.go

* Update client.go

* Update client.go

* Changes according to the review
2022-04-10 01:21:37 +02:00
Mauro Leggieri c7576cc10c Added Windows support and removed some panics (#1264) 2022-04-09 15:38:51 +02:00
zzzzwc f0e1be5665 add nil check of req.body and resp.body on ReleaseBody (#1266) 2022-04-08 18:56:18 +02:00
Erik Dubbelboer 7a5afddf5b Use %v for errors and %q for strings (#1262)
Mostly in tests.
v1.35.0
2022-04-01 18:11:16 +02:00
Cam Sweeney e4a541ff02 support adding/removing clients from LBClient (#1243)
* 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>
2022-04-01 18:10:46 +02:00
Erik Dubbelboer b4152d1a99 Only set RequestCtx.s once
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
2022-04-01 15:56:02 +02:00
Erik Dubbelboer d4c739eee5 State active (#1260)
* Require at least Go 1.15

* Fix StateActive state

* Don't panic when idle connections get closed
2022-04-01 10:18:48 +02:00
Aoang f3bce3aa6e Add Go 1.18 support (#1253)
* Add Go 1.18 support

* fix Gosec Security Scanner

https://github.com/valyala/fasthttp/runs/5595618634?check_suite_focus=true

* fix https://github.com/securego/gosec/issues/469#issuecomment-1070608395 Gosec Github Action Doesn't Work at Go 1.18

* fix https://github.com/golangci/golangci-lint/pull/2438 golangci/golangci-lint Doesn't Work at Go 1.18

* fix golint unused

* fix golint: SA1019: netErr.Temporary is deprecated

* fix https://github.com/valyala/fasthttp/issues/1256
2022-03-20 14:34:31 +01:00
Erik Dubbelboer c6742630ef Fix race conditions in tests 2022-03-18 08:28:53 +01:00
ZhangYunHao 286828e256 add a test for AppendQuotedArg (#1255) 2022-03-18 08:19:58 +01:00
tyltr 2044e1e998 reduce unnessary type assart (#1254) 2022-03-18 08:19:34 +01:00
ZhangYunHao 3101938850 Imporve AppendHTMLEscape fast path (#1249) 2022-03-17 14:52:47 +01:00
Nick Rosbrook d1753f75a7 bytesconv: add appropriate build tags for s390x (#1250)
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.
2022-03-16 17:31:04 +01:00
Y.Horie 8f5e51f0e9 Add connection pool queuing strategies in HostClient. (#1238)
* At first, we implement LIFO(conventional) and FIFO which indicate in #1236
* Change default strategy FIFO
2022-03-15 09:40:26 +01:00
ZhangYunHao f7423e3def Fix AppendHTMLEscape (#1248) 2022-03-15 09:39:40 +01:00
ArminBTVS 1a5f2f40c6 Read response when client closes connection #1232 (#1233)
* 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
2022-03-14 10:53:16 +01:00
Mikhail Faraponov 59f94a3f71 Update github.com/klauspost/compress (#1237) v1.34.0 2022-03-06 13:33:58 +01:00
Erik Dubbelboer 62c15a5d09 Don't reset RequestCtx.s (#1234)
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
2022-03-04 10:02:47 +01:00
Erik Dubbelboer 7670c6eaa6 Fix windows tests (#1235)
* 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
2022-03-04 10:02:31 +01:00
Rennbon f54ffa14ac feature: Keep the memory usage of the service at a stable level (#1216)
* 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>
2022-03-03 13:46:32 +01:00