Commit Graph

293 Commits

Author SHA1 Message Date
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
Marcelo Pires ccaae97f5b Support {readTimeout,maxBodySize,writeTimeout} per request based on the headers. (#598) 2019-07-12 14:42:07 +02:00
Erik Dubbelboer a0248ed3a1 Fix read timeout with nothing read
Fixes #605
2019-07-11 22:10:41 +02:00
losingle 9494955f8e ADD TimeoutWithCodeHandler support (#589)
* ADD TimeoutWithCodeHandler support

* FIX description
2019-06-06 17:17:40 +02:00
Erik Dubbelboer 20ea781823 Add warning to RequestCtx.Error
Fixes #578
2019-05-28 10:46:25 +02:00
xyb 46469b532d Fix comment. (#571)
Signed-off-by: Xiao YongBiao <xyb4638@gmail.com>
2019-05-15 08:31:18 +02:00
Erik Dubbelboer 15dbe35bb5 Timing fixes (#564)
- Improved timing code to be much cleaner
- Add IdleTimeout
- Remove obsolete optimization (was fixed in Go 2 years ago: https://github.com/golang/go/issues/15133#issuecomment-271571395)
2019-04-29 16:12:47 +03:00
Kirill Danshin 517df88332 added option to keep hijacked connection open (#550)
Signed-off-by: Kirill Danshin <kirill@danshin.pro>
2019-03-02 23:01:48 +03:00
Kirill Danshin 64c234a44a reset request before ctx release; fixes #548
Signed-off-by: Kirill Danshin <kirill@danshin.pro>
2019-03-02 09:14:45 +03:00
Tiago Peczenyj 0558e349d7 fix context Err() issue (#544)
* fix context Err() issue

Co-Authored-By: peczenyj <tiago.peczenyj@gmail.com>
2019-02-16 10:53:21 +00:00
Erik Dubbelboer 02b7301203 Fix TechEmpower performance degradation
Fixes #533
2019-02-12 20:34:43 +01:00
Erik Dubbelboer 8b58c26960 Fix ReduceMemoryUsage 2019-02-09 11:30:22 +01:00
Erik Dubbelboer 51532b9517 Shutdown close channel returned by RequestCtx.Done
RequestCtx.Done() now returns a channel that will be closed when
Server.Shutdown() is called.
2019-02-02 12:23:32 +01: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
Shulhan 2f22f20f02 all: fix typo on comments
While at it wrap comments with long lines.
2019-01-30 21:50:28 +01:00
Erik Dubbelboer c3ff460e02 Detect 308 as redirect status code
Same as net/http does.
2019-01-19 15:13:27 +01:00
Okunev Yu Dmitry caea86794c Added method (*Server).GetOpenConnectionsCount() and option DisableSleepWhenConcurrencyLimitsExceeded (#485)
* Change sleep when concurrency limits exceeded.
* Added method (*Server).GetOpenConnectionsCount()
2018-12-13 20:03:52 +06:30
Ciprian Dorin Craciun cd72109b02 Update server to not release read and write buffers if ReduceMemoryUsage is not set 2018-11-21 13:39:55 +06:30
Ciprian Dorin Craciun f9d5eea569 Add note about panic recovery for Server.Handler 2018-11-21 13:37:54 +06:30
Erik Dubbelboer 598a52272a No error response on keep-alive close
Don't return an error response if a keep-alive connection closes either
because the other side closed the connection or a read timeout occurs.

This will prevent net/http from printing
"Unsolicited response received on idle HTTP channel"
when a ReadTimeout is set on the fasthttp Server.

Fixes #465
2018-11-21 13:33:28 +06:30
Erik Dubbelboer efe4585c98 Make RequestCtx implement context.Context
fixes #459
2018-11-16 00:22:29 +08:00
Berezhnoy Pavel e771b6fe43 #457: allow to rewrite system error response (#458)
* #457: allow to rewrite system error response

* #457: review fixes

* #457: more review issues fixed
2018-11-13 15:41:42 +03:00
dgrr 63a0b46e2d Changed hasNextProto name to getNextProto and deleted TODO. 2018-11-12 10:27:32 +05:30
dgrr 3fb1313e33 Changed *tls.Conn by extended connTLSer 2018-11-12 10:27:32 +05:30
dgrr d37102dec8 Fixed NextProto error caused by non-Handshake call.
As you can see here https://golang.org/src/crypto/tls/conn.go#L1041
crypto/tls.Conn does not perform a TLS handshake until Read or Write functions are called.
Then the solution is to call crypto/tls.Conn.Handshake() to check Client values.
2018-11-12 10:27:32 +05:30
Dmitry Yu Okunev 6b0a1c55ef Added a comment to (*Server).GetCurrentConcurrency() 2018-11-03 18:14:29 +05:30
Dmitry Yu Okunev 5684318399 Fixed race-condition of the method (*Server).GetCurrenctConcurrency() 2018-11-03 18:14:29 +05:30
Dmitry Yu Okunev 0915d6166b Added method (*Server).GetCurrenctConcurrency() 2018-11-03 18:14:29 +05:30
Sigalas Alexandros 1b3ac0ccc9 Fix Server.ConnState hook #441 2018-10-28 23:27:08 +05:30
Erik Dubbelboer afcef43292 Add RequestCtx.Conn() method
Fixes #286
2018-10-14 10:38:42 +02:00