Commit Graph

272 Commits

Author SHA1 Message Date
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
Erik Dubbelboer 573be81328 Hopefully fix TestShutdownReuse flakiness 2018-10-14 10:18:21 +02:00
Erik Dubbelboer 8dfc881b9e Added Server.nextProtos
This implementation allows user to handle crypto/tls.Config.NextProtos to use their own handlers for the negotiated TLS protos like HTTP/2.
Workerpool where changed to adapt WorkerFunc to another conns server with ServeConn type and contains the Server structure which creates to check configured protos.
2018-10-05 16:35:59 +08:00
bslizon 761788a34b Add tcp keepalive 2018-09-27 15:22:58 +03:00
bslizon 2e04bb8884 enable TCP keep-alives 2018-09-27 15:22:58 +03:00
Erik Dubbelboer be257bcef6 Improve Shutdown behaviour 2018-09-27 17:38:34 +08:00
Erik Dubbelboer b3b6b8cb28 Fix Request.connectionCloseFast bugs
See https://github.com/valyala/fasthttp/pull/265
and https://github.com/valyala/fasthttp/issues/220
and https://github.com/valyala/fasthttp/issues/264
2018-09-24 21:30:30 +08:00
Erik Dubbelboer 3d4ce5b57c Fix data race errors
Server.Shutdown was causing data race errors. One issue was that it was
possible for sync.WaitGroup.Add() to be called while Shutdown was already
calling .Wait(). To fix this I have removed the WaitGroup and replaced
it with atomic counters and a semi busy wait loop.

Fixes #416
2018-09-24 21:22:40 +08:00
Erik Dubbelboer 1ba43613e8 Clarify how to do relative redirects
Fixes #328
2018-09-20 18:06:11 +08: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
Xu Qiaolun ecb7cbdfb2 call the ConnState callbacks in Server.ServeConn 2018-08-30 15:20:32 +00:00
Xu Qiaolun c88d0992b4 vendor ConnState type in fasthttp package 2018-08-30 15:20:32 +00:00
徐乔伦 69613e6feb add support for http.ConnState
issue #205
2018-08-30 15:20:32 +00:00
Erik Dubbelboer 7c74b1f431 Remove duplicate check
Is already checked at https://github.com/valyala/fasthttp/blob/4a16377d6e780cb75b91962ea2100d83f7452565/http.go#L1190
and https://github.com/valyala/fasthttp/blob/4a16377d6e780cb75b91962ea2100d83f7452565/http.go#L1244
2018-08-27 21:46:12 +00:00
Erik Dubbelboer d689bfcde7 Copy file if rename fails (save multipart)
Renaming a file can fail when the two files are on different devices.
Just copy if rename fails for any reason. If rename fails because of
other reaons copy will either work or fail for the same reason as well
so we won't miss any errors after this.
2018-08-27 21:35:30 +00: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 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
Erik Dubbelboer 3f904e1492 Remove code that does nothing
connTime never changes so the statement does nothing.
2018-08-24 15:50:31 +03:00
Erik Dubbelboer a58298a3a8 Fix doc for some time functions
They still said the return value would be truncated to the nearest
second which is false after ef10ed05a3.
2018-08-21 17:58:36 +03:00