Commit Graph

85 Commits

Author SHA1 Message Date
Erik Dubbelboer df87e7089a Fix race condition in TestCloseIdleConnections
On really slow machines. when the test takes longer than 10 seconds,
mCleaner can already delete the connection from the map before we
check it again.
2020-11-06 12:00:12 +01:00
Erik Dubbelboer ae8b65fa62 Add Client.CloseIdleConnections() 2020-09-13 13:58:13 +02:00
Erik Dubbelboer 34a61fe63f Update linting (#851) 2020-07-17 14:22:28 +02:00
Erik Dubbelboer 9dd7979b2e Restart PipelineClient worker on error (#834) 2020-06-16 11:58:07 +02:00
Vural Kap 77dcda39ae Add custom retry decider for fail http requests 2020-05-27 20:40:04 +03:00
Erik Dubbelboer 123f6a8cee Fix memory reusage bug with auth
Fixes #814
2020-05-25 20:27:15 +02:00
Erik Dubbelboer d22782d3f7 HostClient can't switch between protocols (#800) 2020-05-18 18:30:29 +02:00
Erik Dubbelboer 05d4602a68 Fix race condition in test 2020-05-16 11:54:57 +02:00
Erik Dubbelboer dacd0353f9 HostClient can't switch between protocols 2020-05-02 21:01:52 +02:00
Erik Dubbelboer 079f39bddc Don't allow ASCII control character in URLs (#790)
* Don't allow ASCII control character in URLs

* Add tests
2020-04-25 20:54:59 +02:00
Daniel Qian 70b1d3bce7 feat: make client to wait when no free connections (#764)
* feat: make client to wait when no free connections

* feat: make client to wait when no free connections

use AcquireTimer to do timeout instead of using context

* feat: make client to wait when no free connections

Add BenchmarkClientGetEndToEndWaitConn* to test heap allocation
in waiting for free connection situation

* feat: make client to wait when no free connections

Add BenchmarkHTTPClientGetEndToEndWaitConn* to test heap allocation
in waiting for free connection situation

* feat: make client to wait when no free connections

fix bug in BenchmarkHTTPClientGetEndToEndWaitConn*

* feat: make client to wait when no free connections

fix bug in TestHostClientMaxConnWaitTimeoutSuccess make it wait
longer to avoid ErrNoFreeConns on travis-ci

* feat: make client to wait when no free connections

fix do not compile benchmark(NetHTTP?)ClientGetEndToEndWaitConn
if go version < 1.11.x

* feat: make client to wait when no free connections

fix the bug that if deadline is earlier than MaxConnWaitTimeout,
still wait MaxConnWaitTimeout which later than deadline.

* feat: make client to wait when no free connections

fix race condition in TestHostClientMaxConnWaitTimeoutError

* feat: make client to wait when no free connections

fix bug in TestHostClientMaxConnWaitTimeoutWithEarlierDeadline
2020-04-03 17:12:50 +02:00
Erik Dubbelboer 0ba26f7b42 Don't retry requests with a BodyStream
We won't be able to re-read the body stream. So instead return an error.

Fixes #766
2020-03-30 22:33:31 +02:00
Tomás Senart 75c6008129 client: Implement DoRedirects (#765)
This commit adds a `DoRedirects` method to both `HostClient` and
`Client` as well as top level convenience function of the same name that
is called with the package level `defaultClient`.

Re-implementing this redirect logic in user code is harder than
necessary.
2020-03-25 17:55:13 +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 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
Erik Dubbelboer ec2e3965a4 Don't run TestClientNilResp in parallel 2019-10-19 22:34:56 +02:00
Erik Dubbelboer d428e1b05e Fix race condition in tests, fix URI bug
- Some tests can't be run in parallel.
- `URI` had a pointer to `RequestHeader` which was updated with
`RequestHeader.CopyTo` which resulted in the URI pointing to the wrong
`RequestHeader` causing bugs and race conditions.

The only reason `URI` contained a pointer to `RequestHeader` was to delay the
call to `RequestHeader.Host()` until really needed. But these days instead
of parsing all headers, `RequestHeader.Host()` uses
`RequestHeader.peekRawHeader()` which is rather fast. So we can remove the
pointer in `URI` and completely decouple the two structs improving code
quality and fixing the bug.

For some reason this results in faster code on average as well:
benchmark                                          old ns/op     new ns/op     delta
BenchmarkClientGetEndToEnd1Inmemory-8              1189          1369          +15.14%
BenchmarkClientGetEndToEnd10Inmemory-8             1143          1161          +1.57%
BenchmarkClientGetEndToEnd100Inmemory-8            1228          1236          +0.65%
BenchmarkClientGetEndToEnd1000Inmemory-8           1213          1213          +0.00%
BenchmarkClientGetEndToEnd10KInmemory-8            1362          1350          -0.88%
BenchmarkClientEndToEndBigResponse1Inmemory-8      139967        130070        -7.07%
BenchmarkClientEndToEndBigResponse10Inmemory-8     142233        131809        -7.33%
BenchmarkServerGet1ReqPerConn-8                    1726          1593          -7.71%
BenchmarkServerGet2ReqPerConn-8                    882           927           +5.10%
BenchmarkServerGet10ReqPerConn-8                   440           436           -0.91%
BenchmarkServerGet10KReqPerConn-8                  341           339           -0.59%
BenchmarkServerPost1ReqPerConn-8                   1728          1706          -1.27%
BenchmarkServerPost2ReqPerConn-8                   968           963           -0.52%
BenchmarkServerPost10ReqPerConn-8                  506           505           -0.20%
BenchmarkServerPost10KReqPerConn-8                 424           420           -0.94%
BenchmarkServerGet1ReqPerConn10KClients-8          1117          1051          -5.91%
BenchmarkServerGet2ReqPerConn10KClients-8          565           514           -9.03%
BenchmarkServerGet10ReqPerConn10KClients-8         390           387           -0.77%
BenchmarkServerGet100ReqPerConn10KClients-8        355           348           -1.97%
BenchmarkServerHijack-8                            339           348           +2.65%
BenchmarkServerMaxConnsPerIP-8                     326           325           -0.31%
BenchmarkServerTimeoutError-8                      24355         24180         -0.72%
2019-10-19 21:02:31 +02:00
Erik Dubbelboer c3d82ca3a4 Speed up testing by running tests in parallel 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
Ian Leue ffcdb753b1 Allow client to disable path normalization (#672) 2019-10-11 14:20:29 +08:00
Erik Dubbelboer 1d6a7e0493 The Authorization header should include the Basic keyword
Thanks to https://github.com/paween1980
2019-09-27 17:29:44 +02:00
Mike Faraponov ce02b85a9c Add ability to set timeout for handshake (#631)
* Fixed issue with handshake timeout
2019-08-18 14:34:47 +02:00
Erik Dubbelboer 2edabf3b76 Add support for user:pass in URLs (#614)
Fixes #609
2019-08-18 11:23:33 +02:00
Maxim Lebedev f544170d63 Added methods constants (#567)
*  Added methods constants

* 👌 Fixed methods comment due to review changes
2019-05-06 17:54:49 +02:00
Erik Dubbelboer ea427d2f44 Fix nil Response support in Do* methods
Fixes #561
2019-04-11 19:30:20 +02:00
xuecai 10b98c2cdf add conn's address info in Response (#537)
* reset commit
* fix response copy bug; add tests;
2019-02-16 10:50:14 +00: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
Erik Dubbelboer 192515395f Add Client.NoDefaultUserAgentHeader 2018-11-01 12:44:17 +08:00
Gabriel Pérez S 996610f021 Schema changes detection with HostClient
Related with the issue https://github.com/valyala/fasthttp/issues/244
2018-10-14 16:19:09 +03:00
Erik Dubbelboer c67f81e5f9 Use PostArgs in client
See: https://github.com/erikdubbelboer/fasthttp/issues/17
2018-09-20 15:22:18 +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 d7688109a5 Reset all fields when releasing a clientConn
This fixes a bug where a previous read deadline timer would be reused
for a new connection preventing Client.ReadTimeout from working
properly.

See: https://github.com/valyala/fasthttp/pull/259
2018-09-01 13:20:36 +08:00
Erik Dubbelboer 5576019a85 Fix bug that prevents custom user-agents 2018-08-24 15:31:04 +03:00
Erik Dubbelboer 6fd423aac4 Use and InmemoryListener for TestClientFollowRedirects
Prevents travis-ci from throwing:
client_test.go:489: unexpected error: listen tcp4 127.0.0.1:55234: bind:
address already in use
2018-08-18 01:06:36 +08:00
Kirill Danshin fb5347a023 Merge pull request #231 from erikdubbelboer/testport
Use random ports for tests
2018-08-13 00:51:23 +03:00
Aliaksandr Valialkin b43f17d9a9 Added a test that verifies that the client sends all the request headers and body to the server 2017-09-04 13:47:21 +03:00
Erik Dubbelboer 5afdf7cdfd Use random ports for tests
This should stop travis-ci from constantly failing with
"bind: address already in use"
2017-02-14 14:47:15 +08:00
Aliaksandr Valialkin b0de56d13b Properly set "https" scheme in RequestCtx.URI() for TLS connections 2017-01-15 00:26:21 +02:00
Aliaksandr Valialkin 1c39678a4d client: retry non-idempotent requests if the server closes idle keep-alive connection before receiving the next request
This case usually appears when working with Apache or nginx servers.
See http://httpd.apache.org/docs/2.4/mod/core.html#keepalivetimeout
and http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout
2016-11-28 11:50:36 +02:00
Aliaksandr Valialkin 8ab3351f0a Unshadow err in client test 2016-10-13 17:42:25 +03:00
Aliaksandr Valialkin 93c15ed83c Remove unused variables 2016-10-13 17:40:57 +03:00
Aliaksandr Valialkin 4ca4d0ea09 Client, HostClient, PipelineClient: verify TLS server name 2016-10-12 19:49:23 +03:00
Aliaksandr Valialkin 07f692d02d Revert "Redirection support for Do(*Request, *Response)"
This breaks Get*() with redirects. DoFollowRedirects must be implemented
on top of Do() instead of hacking on internal doRequestFollowRedirects.

This reverts commit 6438022109.
2016-10-05 12:44:51 +03:00
Sick Yoon 6438022109 Redirection support for Do(*Request, *Response) 2016-10-05 12:37:18 +03:00
Aliaksandr Valialkin a52a42acd6 Added HostClient.PendingRequests(), which may be used for balancing load among multiple HostClient instances 2016-09-21 23:03:30 +03:00
Aliaksandr Valialkin 4f66eb3fbb Do not busy wait on free connection in DoDeadline and DoTimeout, since this may result in a lot of goroutines stalled in the busy wait for free connections 2016-09-12 14:19:13 +03:00
Nicolas Bazire 9f7999be97 fix DoDeadline side effect when no free conn (#145) 2016-08-17 20:24:33 +03:00