Commit Graph

115 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
Erik Dubbelboer cc9db3ab20 Try TravisCI Windows (#828)
* Try TravisCI Windows

* prefork is supported on windows with Reuseport=true

* Bit longer timeouts for tests
2020-06-06 15:57:38 +02:00
Erik Dubbelboer 439185eb57 Run cross compilation and race detector on the latest release only 2020-05-31 17:05:49 +02:00
Erik Dubbelboer 2f92c68a07 Add timeouts to tls Handshake
Fixes #813 which suggested the code.
2020-05-25 20:44:04 +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
Darío 402e095d4d Fixed case when no hijacker is added but no-response is true (#772) 2020-04-07 09:35:05 +02: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
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
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 32793db72d Run golangci-lint using a Github Action 2019-11-16 18:09:28 +01:00
Kevin Burns f82a6460e9 Requests with incomplete bodies no longer cause log noise (#682)
* #660 Incorrect content length

* fix

* unexpected EOF is expected

* Prevent test from panicing should err ever be nil
2019-10-27 15:29:20 +08:00
Erik Dubbelboer c3d82ca3a4 Speed up testing by running tests in parallel 2019-10-16 10:20:13 +02:00
Erik Dubbelboer 352ec7c83e Use Fatal instead of Fatalf when no formatting used 2019-10-16 10:20:13 +02:00
Erik Dubbelboer 9dbe5fc77c Don't allow spaces in request header keys
See: https://github.com/golang/go/commit/6e6f4aaf70c8b1cc81e65a26332aa9409de03ad8

Reject any non GET or HEAD requests with a 400.

We can't reject GET or HEAD requests with bad headers as we delay
parsing of these headers until the user asks for one. So in this case we
just ignore the header and don't return a value for it.
2019-10-16 10:20:13 +02:00
Marcelo Pires ccaae97f5b Support {readTimeout,maxBodySize,writeTimeout} per request based on the headers. (#598) 2019-07-12 14:42:07 +02:00
Maxim Lebedev d3715c361c Used Headers constants instead raw strings 2019-05-28 18:04:24 +03: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
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 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
Erik Dubbelboer 9793e28938 Add test for ConnState 2019-01-03 22:23:27 +01:00
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
Erik Dubbelboer 573be81328 Hopefully fix TestShutdownReuse flakiness 2018-10-14 10:18:21 +02:00
David Byttow da9ba61e3b Allows for empty content type by default. Fixes #214 2018-09-19 01:28:32 +03:00
Erik Dubbelboer 761869f3f8 Close the file before trying to rename in SaveMultipartFile
On Windows systems it is not possible to rename files that are opened.
2018-09-13 12:39:45 +08:00
Erik Dubbelboer c6fd90e432 Don't suppresses TLS related errors
See https://github.com/valyala/fasthttp/issues/300
2018-09-05 20:07:23 +03:00
Erik Dubbelboer 5b46f8ddc5 Added support for multiple TLS domains
See: https://github.com/erikdubbelboer/fasthttp/pull/24
2018-08-25 20:11:58 +03:00
Erik Dubbelboer 9b72466ae0 Stop random TestServerErrSmallBuffer failures
TestServerErrSmallBuffer had a small race condition where the test would
checkout the output of the logger after the client connection had been
served but before the worker had written the result to the logger.

This new code is also much faster as it doesn't actually use TCP but
just some in memory buffers.
2018-08-25 16:57:27 +03:00
Erik Dubbelboer d84d8ea604 Allow removal of the Server header in responses
his PR adds an option to the Server called `NoDefaultServerHeader` that
allows a user to indicate that neither the Server's `Name` field nor
the `defaultServerName` should be included in the Server's responses
as a `Server` header by default.

Now when `ResponseHeader.AppendBytes` is found to have an empty `server`
field, it simply skips the `Server` header. Previously that method
would write the `defaultServerName` when no value was found. The only
code paths that took advantage of that were ones originating from
`writeErrorResponse`, which now handles setting the server name
directly.

Fixes: https://github.com/valyala/fasthttp/issues/221
2018-08-25 16:00:48 +03:00
Erik Dubbelboer e3d61d58fd Add Server.Shutdown 2018-08-25 01:39:00 +03:00
Erik Dubbelboer cf6f6e7fca Read GET/HEAD body if it exists
Previously, GET/HEAD bodies were not read. The HTTP 1.1 specification
states:

"A server SHOULD read and forward a message-body on any request; if the
request method does not include defined semantics for an entity-body,
then the message-body SHOULD be ignored when handling the request.
I suspect this code is at fault."

This change reads the body on such request and continues the previous
behavior of returning a "Content-Length" of 0 to the application.

See: https://github.com/valyala/fasthttp/issues/159
2018-08-24 16:21:17 +03:00
Aliaksandr Valialkin 70ceaddfae Added RequestCtx.String that returns unique string representation of the request context 2017-10-18 15:53:05 +03:00
Aliaksandr Valialkin 103adc311e Do not compress responses with sizes smaller than 200 bytes
Compressing small bodies has little sense, since the compressed result size
may exceed the original body size.

This should save CPU time when the server responds with small responses.
2017-05-17 16:17:53 +03:00
Aliaksandr Valialkin b0de56d13b Properly set "https" scheme in RequestCtx.URI() for TLS connections 2017-01-15 00:26:21 +02:00
Aliaksandr Valialkin 21021ceb31 Added a test for redirecting from https to schemeless url 2017-01-14 23:40:56 +02:00
Aliaksandr Valialkin 1913bdea45 Set 'Connection: close' response header when server couldn't parse or accept incoming request 2016-11-17 13:50:15 +02:00
Aliaksandr Valialkin e0618f8ef5 an attempt to localize travis failure on TestServerErrSmallBuffer 2016-11-14 22:56:00 +02:00
Aliaksandr Valialkin 78e415082d an attempt to fix travis build 2016-11-14 22:40:43 +02:00
Aliaksandr Valialkin 02fe9b8533 Issue #173: return valid response instead of silently closing connection on request parsing errors 2016-11-10 18:09:23 +02:00
Aliaksandr Valialkin 935c556b36 Added RequestCtx.Hijacked method for determining whether the underlying connection is hijacked 2016-10-21 14:33:22 +03:00
Aliaksandr Valialkin e0c9f3d5ff typo fixes in comments 2016-10-13 17:39:06 +03:00
Aliaksandr Valialkin 2662f2e1f4 Allow redirecting to urls without scheme, i.e. //google.com/foo.bar 2016-08-17 18:55:32 +03:00
Aliaksandr Valialkin 5210f60181 Detect overriden TLS connections in RequestCtx.IsTLS and RequestCtx.TLSConnectionState 2016-08-17 18:01:59 +03:00
Gerasimos Maropoulos 006fac3cba Implement VisitUserValues - https://github.com/valyala/fasthttp/issues/126 (#129) 2016-07-12 09:40:24 +03:00
Aliaksandr Valialkin d42167fd04 Set response Server header to Server.Name if it is empty. This properly handles #118 2016-06-17 13:13:04 +03:00
Aliaksandr Valialkin efbb037c40 Added RequestCtx.Redirect tests, which cover cases mentioned in https://github.com/kataras/iris/issues/173 2016-06-07 13:30:42 +03:00
Aliaksandr Valialkin 3c5ba2c98d Limit the number of concurrently running request handlers inside TimeoutHandler 2016-06-06 16:47:02 +03:00