Commit Graph

259 Commits

Author SHA1 Message Date
Oleksandr Redko bc70d31d17 refactor: fix revive.indent-error-flow lint issues (#1896) 2024-11-10 20:09:27 +08:00
Erik Dubbelboer c3050516d9 Fix lint and security issues
gosec was failing after the last update introduced some new checks.
2024-09-07 15:22:05 +02:00
newacorn 4616630d57 Remove a redundant field and clarify the comments. (#1851) 2024-09-01 22:39:37 +02:00
newacorn b33e869e2e Another implementation of RetryIfErr (#1850)
* Support for delayed retry logic
* Support for resetting the request timeout before retrying
* Users can decide whether to retry based on the request error and the number of retries.
Estimating the time required for a request to complete is relatively straightforward, but when retries are factored in, it becomes challenging to gauge this time accurately.
2024-09-01 09:17:10 +02:00
newacorn d5c7d8953d fix: The client write operation did not immediately return upon encountering an RST packet. (#1849)
The current client implementation does not immediately return when encountering an RST packet while sending a request, but instead ignores it. This behavior is inconsistent with the net/http package and does not make logical sense.
2024-08-31 14:52:13 +02:00
Kashiwa 25c52d7034 Make RetryIfFunc handle request errors (#1818)
* Make RetryIfFunc handle request errors.

* Replace interface{} to any

* Add field RetryIfErr to fix issue 1744

* Fix linter error
2024-08-25 16:14:02 +02:00
newacorn 5cc0ea1ec3 Fix the MaxConns semaphore issue in HostClient. (#1831)
Fix the MaxConns semaphore issue in HostClient.

Currently, the conns length and connsCount count in HostClient do not correctly implement the MaxConns semaphore mechanism.
This fix ensures that the waiter wake-up chain does not break.
2024-08-20 23:24:01 +02:00
newacorn 3cdc6f124a TestHostClientMaxConnWaitTimeoutError test case sometimes fails (#1832)
The current implementation makes some incorrect assumptions about observing changes in the state of wantConn.
2024-08-20 23:23:43 +02:00
Erik Dubbelboer df8335f9ab A response without a body can't have trailers (#1825) 2024-08-20 23:10:04 +02:00
Juan Calderon-Perez 1fb3453165 Use Named Fields and Align Structures to Reduce Memory Usage (#1814)
* Use Named fields and Align Structures to Reduce Memory Usage

* Remove extra spaces
2024-08-02 22:26:52 +02:00
Kashiwa 86c7e844f4 Optimize struct field order to reduce memory usage (#1809)
1. Reduce RequestHeader from 368 bytes to 360 bytes
2. Reduce Request from 816 bytes to 800 bytes
3. Reduce Response from 432 bytes to 416 bytes
4. Reduce Client from 312 bytes to 288 bytes
5. Reduce HostClient from 416 bytes to 392 bytes
6. Reduce PipelineClient from 176 bytes to 168 bytes
7. Reduce pipelineConnClient from 216 bytes to 208 bytes
8. Reduce Cookie from 232 bytes to 224 bytes
9. Reduce FS from 184 bytes to 160 bytes
10. Reduce fsHandler from 168 bytes to 160 bytes
11. Reduce ResponseHeader from 328 bytes to 320 bytes
12. Reduce headerScanner from 128 bytes to 120 bytes
13. Reduce TCPDialer from 104 bytes to 96 bytes
14. Reduce workerPool from 152 btyes to 144 btyes
2024-07-20 19:20:26 +02:00
Erik Dubbelboer a8fa9c04b4 Don't allow , in host when using Client (#1761)
When using a url like http://example.com,/ URI will parse "example.com,"
as host. HostClient then splits this by "," into multiple addresses and
will connect to example.com. HostClient splitting the address by "," is
only for direct use, not for use with Client.
2024-04-29 10:48:09 +02:00
Max Denushev 57b9352ad1 fix: propagate body stream error to close function (#1743) (#1757)
* fix: propagate body stream error to close function (#1743)

* fix: http test

* fix: close body stream with error in encoding functions

* fix: lint

---------

Co-authored-by: Max Denushev <denushev@tochka.com>
2024-04-22 08:45:33 +02:00
Oleksandr Redko 28615eba55 Change empty string checks to be more idiomatic (#1684) 2024-01-04 15:05:38 +01:00
Oleksandr Redko 9d6b470260 chore: Add missing dots at the end of comments (#1677) 2023-12-13 13:56:24 +08:00
Oleksandr Redko 12949de784 chore: Set max line length to 130 characters (#1676) 2023-12-05 19:49:41 +01:00
Aviv Carmi 8ca7a9c89c add support for custom dial function with timeouts (#1669)
* add support for custom dial function with timeouts

* fix linting

---------

Co-authored-by: Aviv Carmi <aviv@perimeterx.com>
2023-11-27 13:46:43 +01:00
Oleksandr Redko f196617f55 chore: Use 'any' instead of 'interface{}' (#1666)
gofmt -w -r "interface{} -> any" -l .
2023-11-24 11:33:04 +01:00
Oleksandr Redko 8ecfc989d9 Enable dupword, unconvert linters (#1658) 2023-11-12 16:42:39 +01:00
Erik Dubbelboer 3267649442 Fix spelling mistake
Fixes #1654
2023-11-10 11:33:33 +01:00
Scott Kidder 42bd7bb7e2 Allow redirect URI path to not be normalized. (#1638)
* Allow redirect URI path to not be normalized.

* Introduce DisableRedirectPathNormalizing field to Request

* Use field name as start of comment.

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

---------

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-10-30 19:08:51 +01:00
chenyunfei 772e4aadb7 BUGFIX: HostClient.DialDualStack not work when using DoDeadline (#1634)
Co-authored-by: chenyunfei.cs <chenyunfei.cs@bytedance.com>
2023-10-21 12:38:07 +02:00
Erik Dubbelboer 8cc5539af7 Fix various request timeout issues
A timeout of 0 should timeout immediately. When retrying requests the
timeout should be updated to reflect the already passed time

Fixes https://github.com/valyala/fasthttp/issues/1617
2023-09-09 14:28:52 +02:00
Armin Becher 34e7da1f1b Allow connection close for custom streams (#1603)
* feat: allow connection close for custom streams

* fix: avoid req access since might already be released

* fix: fix aloc test fails

* fix: race condition when clossing body stream
2023-09-02 17:56:18 +02:00
Oleksandr Redko 4ec5c5a774 docs: fix typos in comments and tests 2023-08-30 14:13:13 +02:00
Oleksandr Redko 9aa666e814 Enable gocritic linter; fix lint issues (#1612) 2023-08-29 20:08:37 +02:00
Erik Dubbelboer 0e99e64ee8 Update golangci-lint and gosec (#1609) 2023-08-26 12:49:17 +02:00
Tim 54fdc7a73c Abstracts the RoundTripper interface and provides a default implement (#1602)
* Abstracts the RoundTripper interface and provides a default implementation for enhanced extensibility (#1601)

* test: Add custom transport test case (#1601)

* Make default RoundTripper implmention none public

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

---------

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-08-10 09:43:26 +02:00
Oleksandr Redko d229959216 Remove unnecessary indent blocks (#1586) 2023-06-26 14:13:16 +02:00
Erik Dubbelboer e6ce5f0b11 Remove invalid documentation
The Timeout functions don't use separate goroutines anymore and use
normaly deadlines. Because of that requests are terminated and don't
keep running in the background as before.
2023-05-22 16:27:56 +02:00
byte0o 9bc8e480c4 Request timeout settings for the same domain name are reused (#1558)
* Update client.go

fix client http SetReadDeadline/SetWriteDeadline Deadline is reused

* delete Deadline comments  fix test singleEchoConn implement SetWriteDeadline/SetReadDeadline

* fix test SetReadDeadline/SetWriteDeadline none implement

---------

Co-authored-by: gaoping <gaoping1@wps.cn>
2023-05-14 12:55:02 +02:00
Zhengkai Wang d2f97fc426 fix the problem: HostClient maybe delete when pendingClientRequests > 0 (#1562)
* add the functions to get host clients

* add concurrency for client's HostClient map

* delete test code

* add lock in once block

* fix the problem: HostClient maybe delete when pendingClientRequests > 0

* fix the problem: HostClient maybe delete when pendingClientRequests > 0

---------

Co-authored-by: wangzhengkai.wzk <wangzhengkai.wzk@alibaba-inc.com>
2023-05-12 09:49:37 +02:00
Zhengkai Wang 7ea3b6330e add concurrency for client's HostClient map (#1550)
* add the functions to get host clients

* add concurrency for client's HostClient map

* delete test code

* add lock in once block

---------

Co-authored-by: wangzhengkai.wzk <wangzhengkai.wzk@alibaba-inc.com>
2023-05-11 10:07:58 +02:00
kukayiyi 87cb886157 client:Fix DoTimeout timeout failure by setting temporary dial (#1535) 2023-04-15 13:39:32 +02:00
Anthony-Dong 6b958c2c22 support response body stream (#1414)
* feat: support response body stream

* style: add header interface

* Update http.go

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

* feat: support request、response、client stream

* fix: close reader bug

---------

Co-authored-by: fanhaodong.516 <fanhaodong.516@bytedance.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-04-05 18:56:31 +02:00
LeoSun 239cce45b1 format : update some codes style (#1533)
* update some codes style

* update adaptor.go and client.go

* Update fasthttpproxy/http.go

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

---------

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-04-04 13:48:48 -07:00
Moritz Poldrack d0f2727a4d get rid of some panics (#1526)
* client: simplify (*HostClient).do()

Remove an allocation in favour of deferring a call to release the
response.

* client: remove panic in dialAddr

Return an error instead of panicking if the user supplied a nonsensical
DialFunc.

* compression: remove panic on invalid compression level

If a compression level exceeding gzip's boundaries is provided, fasthttp
will panic. Instead it would be better to handle this error for them by
limiting it to the minimum or maximum value, depending on the direction
the user has exceeded the limits.

Clamp the value of gzip to always be between gzip.BestSpeed and
gzip.BestCompression.

* peripconn: remove panic on negative connection count

When a negative count is reached when unregistering a connection, a
panic is caused even though data-integrity is not at risk.

Replace the panic() with a simple clamp on the value to ensure the
value does not exceed it's expected lower bounds.

References: #1504

* compress: remove error on failed nonblocking writes

Since there is no way of handling or even logging non-critical errors in
stateless non-blocking writecalls, just drop them and hope the user
notices and tries again.

* workerPool: remove panic on redundant Start and Stop calls

Instead of panicking for invalid behaviour, it's preferable to just turn
the function into a noop.

* http: remove panic on invalid form boundary

* http: remove panic on negative reads

Since bufio already panics on negative reads, it is not necessary to do
so as well. If the length is zero and for some reason no error is
returned, readBodyIdentity and appendBodyFixedSize now errors in these
cases.

Link: https://github.com/golang/go/blob/851f6fd61425c810959c7ab51e6dc86f8a63c970/src/bufio/bufio.go#L246

* fs: remove panic on negative reader count

When a negative count is reached when unregistering a reader, a panic is
thrown even though data-integrity is not at risk.

Replace the panic() with a simple clamp on the value to ensure the
value does not exceed it's expected lower bounds.

* server: remove panic in favour of a segfault

Panicking with "BUG: " obscures the error. As the segfault causes a
panic anyway, just let the chaos unfold.

* server: remove panic in favour of returning an error

Writing on a timed-out response is not endangering data integrity and
just fails.

* chore: add comments to all panics

* chore: fix minor typo
2023-03-30 03:38:28 +02:00
Oleksandr Redko a281f1d21f client: HostClient.Do hangs out when ErrConnPoolStrategyNotImpl (#1515) 2023-03-14 22:36:38 +01:00
Oleksandr Redko 7846101dc6 client: fix Do hangs when configure host client fails (#1514) 2023-03-11 17:48:33 +01:00
Oleksandr Redko a9d57a9461 client: remove unused go:build comment (#1511) 2023-03-06 17:08:11 +01:00
Igor Menshenin 74a050705b Immediately return ErrTimeout if deadline is already reached. (#1497)
* fix: Immediately return ErrTimeout if deadline is already reached.

* test: Added tests for negative timeout

---------

Co-authored-by: Igor Menshenin <igor@native.rent>
2023-03-03 21:25:39 +01:00
cui fliter ac631aa4eb fix functiom name (#1505)
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-03-03 17:43:44 +01:00
Oleksandr Redko e15a810a98 docs: fix grammar issues and typos in comments (#1492) 2023-02-13 10:43:44 +08:00
Oleksandr Redko 934f04e330 Refactor golangci-lint config and remove redundant nolints (#1486)
* Refactor golangci-lint config

- Use golangci-lint-action for GitHub workflow.
- Add additional golangci-lint run options.
- Remove unused nolint directives.

* Revert exclude-use-default option
2023-02-11 15:35:15 +08:00
Oleksandr Redko f84e2346ba Rename unexported funcs, vars to match common Go (#1488)
See https://github.com/golang/go/wiki/CodeReviewComments#initialisms
and https://go.dev/doc/effective_go#mixed-caps
2023-02-10 21:34:49 +08:00
Oleksandr Redko c0c5f9cd38 doc,test: correct typos (#1484) 2023-02-09 09:29:28 +01:00
Sergey Ponomarev 51048b0620 client.go Simplify default UA logic (#1466)
The getClientName() checks if !NoDefaultUserAgentHeader then returns the Client.Name field.
But it also saves it to atomic field clientName. This is not needed and logic can be simplified.
Previously the clientName vas a byte slice that was copied from c.Name and cached. See 02e0722fb7

Fix #1458
2023-01-02 12:51:39 +08:00
Xuran e46afc3ae3 fix: client may remove hostclient incorrectly (#1461) 2022-12-29 19:18:27 +08:00
Sergey Ponomarev c50de95952 client.go fix addMissingPort() (#1444)
* client.go Make addMissingPort() public

It's needed for those who creates the instance of the HostClient manually.

* client.go fix AddMissingPort()

Previously for IPv6 addresses the default port wasn't added.
The fix adding a test and optimization that should avoid itoa() call and reduce a memory usage
2022-11-28 08:06:09 +01:00
Andy Pan 8f434434e7 Wait for the response of pipelineWork in background and return it to pool (#1436) 2022-11-17 06:31:03 +01:00