Commit Graph

133 Commits

Author SHA1 Message Date
Erik Dubbelboer c2b317d47d Go 1.26 and golangci-lint updates (#2146)
Keep Go 1.24 compatibility for now (by not using `wg.Go()`).
2026-02-21 10:28:39 +01:00
Aabishkar Aryal e7d310fd76 Add DNS cache management methods for TCPDialer (#2072)
* Add DNS cache management methods for TCPDialer

Resolves #2066

This commit introduces two new methods for managing DNS cache in TCPDialer:

1. FlushDNSCache() - Clears all cached DNS entries, forcing fresh lookups
2. CleanDNSCache() - Removes only expired entries based on DNSCacheDuration

Key changes:
- Add FlushDNSCache() and CleanDNSCache() methods to TCPDialer
- Add global FlushDNSCache() and CleanDNSCache() functions for default dialer
- Refactor tcpAddrsClean() to extract reusable cleanExpiredDNSEntries() method
- Add comprehensive tests with mock resolver to verify caching behavior

Use case: Users can now set longer cache durations (e.g., 30 minutes) and
manually refresh DNS when needed, providing better control over DNS resolution
timing while maintaining performance benefits of caching.

* Remove CleanDNSCache method to reduce the API surface layer and related tests from TCPDialer

* fix: resolve godot linter issue in client_test.go

Add missing period to comment to comply with godot linter rule requiring
comments to end with proper punctuation.
2025-09-25 14:53:57 +08:00
Erik Dubbelboer 4d25421ae5 Drop Go 1.23 support (#2065)
The Go team doesn't support this version anymore. This is required to
update our golang.org/x/... dependencies.
2025-09-10 22:16:01 +02:00
Oleksandr Redko 51b4947320 test: replace atomic operations with atomic types (#2048) 2025-08-07 19:02:12 -04:00
Erik Dubbelboer b1c27881cb Try to fix tests with dial timeouts (#1940)
Use github.com and .io instead of example.com and google.com as they are
probably more reliable within Github actions.
2025-01-15 05:47:54 +01:00
Oleksandr Redko 56fd74b8c0 chore: Upgrade golangci-lint to 1.61.0 (#1887) 2024-10-22 13:03:34 +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
newacorn 3aa972e2fc Fix issues with tests interfering with each other in certain situations. (#1842)
In some cases, the goroutines started by one test do not terminate smoothly before the next round of tests begins, causing interference between tests.

Performance Impact: This results in test completion times not increasing linearly with the count value.

Correctness Impact: It affects the accuracy of memory allocation test cases.
2024-08-31 14:27:05 +02:00
newacorn f789432e77 Fix potential data race reports when the -race flag is enabled. (#1847)
The `testClientDoTimeoutError` and `testClientGetTimeoutSuccess` test function does not immediately return or fatal when the test fails. Instead, it continues to stringify the byte slice that was passed as the `dst` parameter to the `Client.GetTimeout` method. If the test fails due to a timeout, the request may still be ongoing, and there might be a data race between writing to `dst` and the stringification operation.
2024-08-31 14:26:07 +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
Erik Dubbelboer e6d9374bea Fix common recurring CI issues (#1784) 2024-06-02 12:08:27 +02:00
Oleksandr Redko 1c3ba3b2f0 test: replace panic with returning error (#1747) 2024-04-02 17:00:44 +01:00
Oleksandr Redko 7e1fb71854 Enable perfsprint linter; fix up lint issues (#1727) 2024-03-02 16:21:23 +01:00
Oleksandr Redko 190204cf1a Upgrade golangci-lint to v1.56.2; fix gocritic issues (#1722) 2024-02-21 05:51:28 +01:00
Oleksandr Redko 9d6b470260 chore: Add missing dots at the end of comments (#1677) 2023-12-13 13:56:24 +08: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
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
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
Oleksandr Redko 9aa666e814 Enable gocritic linter; fix lint issues (#1612) 2023-08-29 20:08:37 +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
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
Erik Dubbelboer fa72f3cc39 Fix tests (#1552) 2023-05-07 14:32:14 +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
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
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
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
brian-armstrong-discord f095481f00 Request.SetTimeout (#1415)
* Request.SetTimeout

This functionally works the same as e.g. Client.DoTimeout(), but we can
also use it for Client.DoRedirect(). There is no way as far as I can
tell to set a timeout on a DoRedirect call, so this makes it possible.

* tests

* docs
2022-11-03 21:25:19 +01:00
Erik Dubbelboer a5f448fc97 Improve Client timeout (#1346)
Don't run requests in a separate Goroutine anymore. Instead use proper
conn deadlines to enforce timeouts.

- Also contains some linting fixes.
2022-07-29 19:03:15 +02:00
fare83 c94be05897 use timeout insteadof read/writetimeout when timeout lower than read/… (#1336)
* use timeout insteadof read/writetimeout when timeout lower than read/writetimeout

* use deadtime; fix test timeout;

Co-authored-by: 徐焱 <xuyan4@staff.sina.com.cn>
2022-07-06 14:03:50 +02:00
Erik Dubbelboer 7a5afddf5b Use %v for errors and %q for strings (#1262)
Mostly in tests.
2022-04-01 18:11:16 +02:00
Erik Dubbelboer c6742630ef Fix race conditions in tests 2022-03-18 08:28:53 +01:00
ArminBTVS 1a5f2f40c6 Read response when client closes connection #1232 (#1233)
* Read response when client closes connection #1232

* Fix edge case were client responds with invalid header

* Follow linter suggestions for tests

* Changes after review

* Reafactor error check after review

* Handle connection reset on windows

* Remove format string from test where not needed

* Run connection reset tests not on Windows
2022-03-14 10:53:16 +01:00
Sergey Ponomarev 6a3cc2325b uri_test.go use example.com for clearness (#1212)
* uri_test.go replace xxx.com with example.com

* uri_test.go replace foobar.com with example.com

* uri_test.go use example.com inside of testURIUpdate()

* uri_test.go use example.com instead of google.com

* uri_test.go use example.com instead of google.com

* uri_test.go testURIUpdate() host with port
2022-02-09 10:19:34 +01:00
ArminBTVS 8d7953eda7 Fix scheme check for not yet parsed requests (#1203)
* Fix scheme check for not yet parsed requests

At this point the request might not be parsed yet and set. In that case uri is empty and isHttps() returns always false. I don't expect this is intended?

Otherwise URL() must be called before actually passing the request to client.Do()

* Add test

* Please linter
2022-01-31 22:02:58 +08:00
Erik Dubbelboer e9db537178 Use %w to wrap errors (#1175) 2021-12-13 09:41:34 +01:00
Erik Dubbelboer a50f59be52 Increase various test timeouts
Github workers on windows are slow.
2021-08-24 11:18:22 +02:00
Erik Dubbelboer 1504a84ed7 Increase TestHostClientMaxConnWaitTimeoutSuccess timeout 2021-06-29 09:36:30 +02:00
Erik Dubbelboer 874c8cad76 Increase timeouts for Windows github actions 2021-06-18 15:46:40 +02:00
Erik Dubbelboer 410bde6009 Fix race condition in TestPipelineClientIssue832 2021-06-18 15:28:58 +02:00
Erik Dubbelboer 9f2c63676d Lower go test time 2021-06-18 14:57:18 +02:00
Darío be13b504ab Defined Transport for the client (#1045)
* Defined Transport for the client

* Added Transport test
2021-06-16 12:55:56 +02:00
blanet 860c345f10 Fix unexpected panic when calling Do of a PipelineClient (#997)
* fix: Unexpected panic for PipelineClient

PipelineClient would panic when calling `Do` with a nil Response as
the second parm

This commit fixes the unexpected panic by checking nil first before
setting fields for Response

* Add tests to ensure nil resp is valid for PipelineClient
2021-03-17 21:26:56 +01:00
kiyon 02e0722fb7 Add PipelineClient name (#994)
* Improve documentation about DelClientCookie which related with #951.

* Add pipeline name
2021-03-15 17:46:16 +01:00
kiyon 34fa9a603f Add DisableHeaderNamesNormalizing to PipelineClient (#991)
* Improve documentation about DelClientCookie which related with #951.

* Add DisableHeaderNamesNormalizing to PipelineClient
2021-03-05 17:38:46 +01:00
Erik Dubbelboer fbe6a2d470 Add fasthttp.GenerateTestCertificate and use in tests
Remove ssl-cert-snakeoil so our tests don't fail in 2025.
2021-02-06 11:47:11 +01:00
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