Commit Graph

166 Commits

Author SHA1 Message Date
Erik Dubbelboer a995d43d9c Add EnableNormalizing to RequestHeader and ResponseHeader 2020-08-16 09:18:05 +02:00
sky cc8ba4b5a3 Add a api DisableNoDefaultContentType to disable add default content type. (#859)
* Add api DisableNoDefaultContentType to disable add default contentype if no Content-Type header.

* Update test case.

* Update api name.

* Update header.go

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

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2020-08-07 17:38:59 +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 bcaa594b41 Remove unused raw header code 2020-05-31 15:49:37 +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 69d5c3721a Client should return ErrTimeout on timeout (#736)
Not ErrConnectionClosed which is incorrect.

Fixes: https://github.com/valyala/fasthttp/issues/355
2020-01-31 22:21:00 +01:00
Andy Pan 59b28fe0e5 Resolve code issues from goreportcard.com (#725) 2020-01-12 12:57:42 +01:00
Erik Dubbelboer 415e5fc531 Fix panic in header parser 2019-12-14 22:20:09 +01:00
Erik Dubbelboer fd55658938 Improve multiline header parsing (#708)
- Replace tabs with spaces at line starts to match net/http
- Don't allow multi line header names. See: https://github.com/golang/go/issues/34702
2019-12-14 10:58:06 +01:00
tedli 6a8a72ac18 add extra checking of header buffer, to support multi line header value (#123) (#688) 2019-12-14 09:45:35 +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
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
Ciprian Dorin Craciun 85217e0d5e Correctly handle NoDefaultContentType without setting an Content-Type value (#628)
If `NoDefaultContentType` is set, but no actual `Content-Type` header is set, do not send the wrong `Content-Type: ` header
2019-08-13 11:53:03 +02:00
Erik Dubbelboer a0248ed3a1 Fix read timeout with nothing read
Fixes #605
2019-07-11 22:10:41 +02:00
Dair Aidarkhanov 1bd0404ced Removing redundant else statement from HeaderCookie (#596) 2019-07-03 23:40:48 +02:00
Maxim Lebedev d3715c361c Used Headers constants instead raw strings 2019-05-28 18:04:24 +03:00
xuecai ed3793a1e1 add tests for copyto (#545)
* add tests for copyto
* add HeaderCopy Test reflect.DeepEqual
2019-02-17 10:11:45 +00:00
Erik Dubbelboer 6647cb2885 Remove duplicate check
We already compare headers case insensitive so we don't need to compare
two different cases.
2019-02-09 11:29:47 +01:00
Shulhan 2f22f20f02 all: fix typo on comments
While at it wrap comments with long lines.
2019-01-30 21:50:28 +01:00
xuecai 4fb459a45e fix args empty string be changed to boolen (#502)
Add support for empty args
2018-12-30 19:56:58 +01:00
Erik Dubbelboer 2f131ba2b2 Add RequestHeader.VisitAllInOrder 2018-12-27 02:05:20 +03:00
Erik Dubbelboer 5836521d82 Use case-insensitive header value comparison
Fixes #483
2018-11-29 17:45:35 +08:00
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 192515395f Add Client.NoDefaultUserAgentHeader 2018-11-01 12:44:17 +08:00
Erik Dubbelboer 4dfc12997e Add RequestHeader.RawHeaders() 2018-10-05 19:00:55 +03: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
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
David Byttow da9ba61e3b Allows for empty content type by default. Fixes #214 2018-09-19 01:28:32 +03:00
Oleg Kovalov 10a0540dfc Remove redundant else statements 2018-09-14 10:00:13 +08:00
Erik Dubbelboer 869903cf7a Fix Cookie peek
See: https://github.com/valyala/fasthttp/issues/313
2018-09-13 12:42:54 +08:00
Erik Dubbelboer 4d08c11c11 Remove RequestHeader.isGet
This small optimization is not worth the extra code complexity.
2018-09-13 12:36:16 +08:00
Erik Dubbelboer 7796335d5f Do case insensitive comparisons for headers and cookies 2018-09-11 20:07:09 +03: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 b174f54b12 Add method to get cookie from response 2018-08-27 21:46:32 +00:00
Erik Dubbelboer e277e51b15 Add support for ResponseHeader.Peek("Set-Cookie")
See: https://github.com/erikdubbelboer/fasthttp/issues/4
2018-08-27 21:42:16 +00: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 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
Kirill Danshin 4a16377d6e Merge pull request #303 from chebyrash/master
Typo fixes
2018-08-13 23:18:55 +03:00
toyblocks a84dc2dc0e Add missing http methods
Add support for 'CONNECT', 'OPTIONS', 'TRACE' and 'PATCH'
2018-03-12 07:00:21 +09:00
xPushkin f24d00fcc6 A lot of typo fixes 2017-10-08 13:30:35 +01:00
Aliaksandr Valialkin 52a0993b96 Issue #278: more optimizations for normalizeHeaderKey 2017-07-11 10:17:57 +03:00
Aliaksandr Valialkin 952171f61b Issue #278: optimize normalizeHeaderKey a bit
Performance results on amd64:

name                            old time/op  new time/op  delta
NormalizeHeaderKeyCommonCase-4  43.3ns ± 0%  32.6ns ± 1%  -24.80%  (p=0.000 n=9+10)
NormalizeHeaderKeyLowercase-4   42.6ns ± 3%  32.6ns ± 1%  -23.41%  (p=0.000 n=10+10)
NormalizeHeaderKeyUppercase-4   43.5ns ± 1%  32.6ns ± 2%  -25.03%  (p=0.000 n=9+8)

Based on top of https://github.com/valyala/fasthttp/pull/279 .
2017-07-10 14:28:06 +03:00
Aliaksandr Valialkin b154429ca9 Compress responses only if their content-type starts with text/ or application/ 2017-05-17 17:10:29 +03:00
Perelandric 3580c93d02 Make SetMethod slice to zero before appending (#234)
SetMethod appended directly to the `h.method` slice without setting its
length to zero, so multiple calls would create an unexpected value.
2017-02-22 09:48:29 +02:00
Aliaksandr Valialkin 2ada93a6df Document that the cookie passed to ResponseHeader.SetCookie may be re-used after the function returns 2017-01-18 19:20:47 +02:00
Aliaksandr Valialkin ef299a95e2 Fixed TestServerErrSmallBuffer for go 1.6 2016-11-14 23:16:56 +02:00
Aliaksandr Valialkin 3246b4efb5 Issue #173: improve error messages on headers parsing 2016-11-10 20:00:54 +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