Commit Graph

322 Commits

Author SHA1 Message Date
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
Pavel Burak 6937fee923 fix: (useless check), skip Response body if http method HEAD (#1224) 2022-02-20 18:14:24 +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
Kilos Liu 6b55811130 Add MaxIdleWorkerDuration to Server. (#1183) 2021-12-26 07:56:34 +01:00
Sergio VS 258a4c17b4 fix: reset response after reset user values on keep-alive connections (#1176) 2021-12-16 05:27:02 +01:00
Erik Dubbelboer e9db537178 Use %w to wrap errors (#1175) 2021-12-13 09:41:34 +01:00
Sergio VS 017f0aa09d fix: reset request after reset user values on keep-alive connections (#1162)
* fix: reset request after reset user values on keep-alive connections

* test: add test for reset request after reset user values
2021-11-23 11:12:06 +01:00
ichx 3b117f8f1e feat: close idle connections when server shutdown (#1155)
* feat: close idle connections when server shutdown

* Fix redundant code

* Update test

* Update test
2021-11-13 11:53:10 +01:00
ichx a94a2c3253 Remove redundant code (#1154) 2021-11-11 19:40:30 +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
Sergio VS 4cfec1a795 feat: make public Server.TLSConfig (#1128)
* feat: make public Server.TLSConfig

* fix: clone tls config only when ServeTLS, ServeTLSEmbed, ListenAndServeTLS or ListenAndServeTLSEmbed
2021-10-20 20:41:02 +02:00
tyltr 7fdd5261e8 feat: a new userData API Remove (#1117)
* feat:userData new api "delete"

* ctx api `remove`

* rename

* modify
2021-10-08 17:45:45 +02:00
Erik Dubbelboer ffab77a59d Improve return value reusability documentation 2021-10-01 13:38:31 +02:00
tyltr 44d0333ba3 fix: typo (#1105) 2021-09-17 09:16:52 +02:00
Erik Dubbelboer 63211032d4 Various deadline fixes (#1081) 2021-08-28 11:19:32 +02:00
Lanco 0fe8cddd97 Optimize size of Server by moving bool fields (#1077) 2021-08-23 11:27:51 +02:00
Tianyi Song d31e6dbdba Handle perIPConn in RequestCtx.IsTLS() specially (#1064) 2021-08-04 20:15:05 +02:00
Sujit Baniya d0df1e1dde Add ResetUserValues() and test (#1056) 2021-07-01 10:57: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 cec99537fe Add IdleTimeout to Shutdown documentation 2021-06-18 13:38:17 +02:00
Sergio Andrés Virviescas Santana b433ecfcbd Make sure to reset the userValues always and at the exact time (#1027)
* Ensure reset userValues always that release RequestCtx

* Reset userValues after response write and hijack handler are executed
2021-05-22 17:23:41 +02:00
Lauris BH 620f0c83ad Add option for middleware to set custom remote address (#1009)
* Add option for middleware to set custom remote address

* Update Init2 to clear custom context remoteAddr
2021-04-23 13:25:02 +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
AlphaBaby a88030b8fb fix gracefilly shutdown bug, issue #958 (#960)
* fix gracefilly shutdown bug, issue #958

* fix golangci-lint

* add option: CloseOnShutdown into Sever

* Update server.go

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

* Update server.go

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

Co-authored-by: fujianhao3 <fujianhao3@jd.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2021-02-07 21:13:36 +01:00
Kirill Danshin 0956208cc6 Add request body streaming. Fixes #622 (#911)
* Add request body streaming. Fixes #622
* Add test cases for StreamRequestBody

Co-authored-by: Kiyon <kiyonlin@163.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
Co-authored-by: Fiber
2021-02-06 23:03:23 +03:00
Erik Dubbelboer 838d3abc3d Allow concurrent ServeTLS 2021-02-06 10:53:30 +01:00
Erik Dubbelboer bd3513389d Always set Keepalive options
Different versions of Go have different defaults, so we just always set
what the user configured.
2020-12-26 17:01:19 +01:00
Erik Dubbelboer 01acd76daf Allow TimeoutHandler connections to be kept alive (#864) 2020-08-16 09:21:00 +02:00
Erik Dubbelboer 34a61fe63f Update linting (#851) 2020-07-17 14:22:28 +02:00
sky ac51d598dc Make the ErrNothingRead to be exposed. (#827)
* Make the ErrNothingRead to be exposed.

* Update header.go

update annotation.

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2020-06-05 14:12:33 +02:00
Erik Dubbelboer 2f92c68a07 Add timeouts to tls Handshake
Fixes #813 which suggested the code.
2020-05-25 20:44:04 +02:00
Erik Dubbelboer 339ad36634 Add Brotli support
New Functions:

    CompressHandlerBrotliLevel(h RequestHandler, brotliLevel, otherLevel int) RequestHandler
    Request.BodyUnbrotli() ([]byte, error)
    Response.BodyUnbrotli() ([]byte, error)
    AppendBrotliBytesLevel(dst, src []byte, level int) []byte
    WriteBrotliLevel(w io.Writer, p []byte, level int) (int, error)
    WriteBrotli(w io.Writer, p []byte) (int, error)
    AppendBrotliBytes(dst, src []byte) []byte
    WriteUnbrotli(w io.Writer, p []byte) (int, error)
    AppendUnbrotliBytes(dst, src []byte) ([]byte, error)

New Constants:

    CompressBrotliNoCompression
    CompressBrotliBestSpeed
    CompressBrotliBestCompression
    CompressBrotliDefaultCompression

Brotli compression levels are different from gzip/flate. Because of this we have separate level constants and CompressHandlerBrotliLevel takes 2 levels.

I didn't add Brotli support to CompressHandler as this could cause a spike in CPU usage when users upgrade fasthttp.

fasthttp.CompressBrotliDefaultCompression is not the same as
brotli.DefaultCompression. brotli.DefaultCompression is more than twice
as slow as fasthttp.CompressBrotliDefaultCompression which I thought was
unreasonable as default.
2020-05-15 15:36:26 +02:00
Mike MacDermaid 32940977fb allow the expect 100 continue workflow to deny requests (#787)
* allow the expect 100 continue workflow to deny requests

* suggested changes

* update booleans to reflect handler name change
2020-04-27 20:29:02 +02:00
Kirill Danshin f9ef8fc47b update the docs
Signed-off-by: Kirill Danshin <kirill@danshin.pro>
2020-04-19 00:44:47 +03:00
Kirill Danshin cc407796cd fix: s.concurrency stays 0 when you don't use s.ServeConn
Signed-off-by: Kirill Danshin <kirill@danshin.pro>
2020-04-19 00:44:47 +03: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
Darío 402e095d4d Fixed case when no hijacker is added but no-response is true (#772) 2020-04-07 09:35:05 +02:00
Andy Pan 0b933084a0 Resolve the security issue of GoSec (#762)
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2020-03-13 11:25:27 +01:00
phuslu b71c8c513c Add support for NoDefaultDate option that excludes the sending of the Date header (#758) 2020-03-13 11:00:44 +01:00
Forest Gagnon b8803fe95d increase correctness of open conn count (#738)
Currently, it appears that GetOpenConnectionsCount underreports the
count by 1 after Shutdown has been called. This leads to a confusing
value when servers are gracefully terminating. For instance, if a server
is stuck in graceful termination, and there is one open connection
keeping it alive, GetOpenConnectionsCount would report zero.

This fix removes the decrement while the server is shutting down. It is
not perfect due to the use of two sequential atomic loads, but in the
common case it should return a more correct value overall.
2020-02-07 20:32:31 +01:00
Erik Dubbelboer b0102c9eba Support calling Serve multiple times on a Server (#731)
You can use the following methods in the handler to find out which
listener the connection is coming in on.
RequestCtx.IsTLS()
RequestCtx.LocalAddr()
RequestCtx.Request.Header.Host()
2020-01-23 18:30:36 +01:00
Andy Pan 59b28fe0e5 Resolve code issues from goreportcard.com (#725) 2020-01-12 12:57:42 +01:00
谷月轩 16c53d6b04 Set StatusRequestTimeout when net timeout error occurred (#713) 2019-12-31 12:23:27 +01:00
Erik Dubbelboer 958ed36194 Allow no response to be send when a connection is hijacked (#712)
* Allow no response to be send when a connection is hijacked

At the moment there is always a HTTP response before the connection gets
hijacked. This second option to Hijack() prevents this response from
being send.

Fixes: https://github.com/valyala/fasthttp/issues/698

* Add HijackSetNoResponse method instead
2019-12-29 11:34:55 +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 32de06dba4 Don't start a goroutine when not needed
sync.Once only has the overhead of a single atomic.LoadUint32

Fixes #693
2019-11-16 18:10:44 +01:00
Erik Dubbelboer 32793db72d Run golangci-lint using a Github Action 2019-11-16 18:09:28 +01:00
ZhangYunHao 707b1c1917 Format errors (#679)
* format errors

* Server is a type name

* Fix typo
2019-10-23 20:12:59 +08:00