Commit Graph

1481 Commits

Author SHA1 Message Date
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
Erik Dubbelboer 15262ecf3c Warn about unsafe ServeFile usage (#1228)
See: https://github.com/valyala/fasthttp/issues/1226
2022-03-03 08:51:13 +01:00
Erik Dubbelboer 1116d034d5 Fix panic while reading invalid trailers 2022-03-01 20:50:12 +01:00
Mikhail Faraponov 856ca8e7aa Update dependencies (#1230) 2022-02-28 20:51:08 +01:00
Erik Dubbelboer 6b5bc7bb30 Add windows support to normalizePath
This is probably still not 100% sure and there are still many bugs with
FS on windows. But it's a slight improvement.

Fixes #1226
2022-02-28 11:56:59 +01:00
Erik Dubbelboer f0b0cfe9b2 Don't log ErrBadTrailer by default 2022-02-23 17:12:07 +01:00
Pavel Burak 6937fee923 fix: (useless check), skip Response body if http method HEAD (#1224) 2022-02-20 18:14:24 +01:00
Aoang b85d2a274b Fix http proxy behavior (#1221)
Add Host header fix behavior
https://datatracker.ietf.org/doc/html/rfc7230#section-5.4
2022-02-18 10:52:19 +01:00
Jack.Ju ad8a07a86e RequestHeader support set no default ContentType (#1218) 2022-02-16 15:52:18 +01:00
lin longhjui c94581c005 support configure HostClient (#1214)
Co-authored-by: linlonghui <linlonghui@chandashi.com>
2022-02-15 08:03:54 +01:00
Sergey Ponomarev 632e222c2a Client examples (#1208)
* examples/host_client

* examples/client

* examples/client/client.go refine imports

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

* examples/host_client/hostclient.go refine imports

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

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2022-02-09 11:09:36 +01:00
Sergey Ponomarev 6a3cc2325b uri_test.go use example.com for clearness (#1212)
* uri_test.go replace xxx.com with example.com

* uri_test.go replace foobar.com with example.com

* uri_test.go use example.com inside of testURIUpdate()

* uri_test.go use example.com instead of google.com

* uri_test.go use example.com instead of google.com

* uri_test.go testURIUpdate() host with port
2022-02-09 10:19:34 +01:00
Mikhail Faraponov 9d665e00df Update dependencies (#1204)
Co-authored-by: Mikhail Faraponov <mikefaraponov@Mikhails-MacBook-Pro.local>
2022-02-01 13:09:04 +01:00
ArminBTVS 8d7953eda7 Fix scheme check for not yet parsed requests (#1203)
* Fix scheme check for not yet parsed requests

At this point the request might not be parsed yet and set. In that case uri is empty and isHttps() returns always false. I don't expect this is intended?

Otherwise URL() must be called before actually passing the request to client.Do()

* Add test

* Please linter
2022-01-31 22:02:58 +08:00
tyltr 61aa8b17a2 remove redundant code (#1202) v1.33.0 2022-01-27 03:17:00 +01:00
Sergio VS 436977654a fix(hijack): reuse RequestCtx (#1201)
* fix(hijack): reuse RequestCtx

* fix(test/hijack): increase wait time

* fix(test/hijack): wait for all connections to finish to check responses
2022-01-22 04:54:37 +01:00
Sergio VS 2aca3e8263 fix(hijack): reset userValues after hijack handler execution (#1199)
* fix(hijack): reset userValues after hijack handler execution

* feat: add test

* fix: typo

* fix(test): race condition
2022-01-18 12:45:41 +01:00
Mikhail Faraponov 9123060b3a Updated dependencies (#1194)
Co-authored-by: Mikhail Faraponov <mikefaraponov@Mikhails-MacBook-Pro.local>
2022-01-14 05:01:51 +01:00
Erik Dubbelboer 7eeb00e1cc Make tests less flaky (#1189) v1.32.0 2022-01-10 05:15:30 +01:00
Mikhail Faraponov d19b8727b0 Update tcpdialer.go (#1188) 2022-01-09 16:03:22 +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