Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Follows these guidelines precisely to ensure consistency and maintainability of

## Stack

- Language: Go (Go 1.22+)
- Language: Go (Go 1.27+)
- Framework: Go standard library
- Testing: Go's built-in testing package
- Dependency Management: Go modules
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ A comprehensive Go package for building and executing HTTP requests with advance

## Installation

**Requirements:** Go 1.22 or higher
**Requirements:** Go 1.27 or higher

```bash
go get github.com/slashdevops/httpx
Expand Down
2 changes: 1 addition & 1 deletion example_http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func ExampleNewClientBuilder_connectionPooling() {
Build()

// Reuse connections efficiently across multiple requests
for i := 0; i < 10; i++ {
for i := range 10 {
resp, err := client.Get(fmt.Sprintf("https://api.example.com/items/%d", i))
if err != nil {
log.Printf("Request %d failed: %v", i, err)
Expand Down
14 changes: 7 additions & 7 deletions example_http_retrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

// Example demonstrates using exponential backoff.
func Example() {
var requestCount int32
var requestCount atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
count := atomic.AddInt32(&requestCount, 1)
count := requestCount.Add(1)
if count <= 3 { // Fail first 3 times
fmt.Printf("Server: Request %d -> 500 Internal Server Error\n", count)
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -60,11 +60,11 @@ func Example() {
// ExampleNewHTTPRetryClient_withExistingAuth demonstrates how the default client
// transparently preserves existing authentication headers in requests.
func ExampleNewHTTPRetryClient_withExistingAuth() {
var requestCount int32
var requestCount atomic.Int32

// Create a server that requires authentication
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
count := atomic.AddInt32(&requestCount, 1)
count := requestCount.Add(1)
auth := r.Header.Get("Authorization")

if auth == "" {
Expand Down Expand Up @@ -107,7 +107,7 @@ func ExampleNewHTTPRetryClient_withExistingAuth() {

body, _ := io.ReadAll(resp.Body)
fmt.Printf("Client: Success! Status=%s, Body='%s'\n", resp.Status, string(body))
fmt.Printf("Client: Auth header preserved through %d retries\n", atomic.LoadInt32(&requestCount))
fmt.Printf("Client: Auth header preserved through %d retries\n", requestCount.Load())

// Output:
// Client: Making authenticated request...
Expand Down Expand Up @@ -167,11 +167,11 @@ func ExampleNewClientBuilder_transparent() {
// ExampleNewHTTPRetryClient_withCustomTransport demonstrates using a custom base transport
// with specific transport settings while maintaining transparent retry behavior.
func ExampleNewHTTPRetryClient_withCustomTransport() {
var requestCount int32
var requestCount atomic.Int32

// Create a test server that fails initially to show retry behavior with custom transport
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
count := atomic.AddInt32(&requestCount, 1)
count := requestCount.Add(1)
fmt.Printf("Server: Request %d from custom transport\n", count)

if count <= 1 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/slashdevops/httpx

go 1.22.0
go 1.27.1
8 changes: 4 additions & 4 deletions http_retrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ func TestRetryTransport_ServerExceedsClientTimeout(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(500 * time.Millisecond) // Server delays response
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
_, _ = w.Write([]byte("OK"))
}))
defer server.Close()

Expand Down Expand Up @@ -942,7 +942,7 @@ func TestRetryTransport_LargeTimeoutPreserved(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(200 * time.Millisecond) // Simulate slow response
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
_, _ = w.Write([]byte("OK"))
}))
defer server.Close()

Expand Down Expand Up @@ -979,7 +979,7 @@ func TestRetryTransport_ContextTimeout(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(500 * time.Millisecond)
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
_, _ = w.Write([]byte("OK"))
}))
defer server.Close()

Expand Down Expand Up @@ -1014,7 +1014,7 @@ func TestRetryTransport_ContextCancellation(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(500 * time.Millisecond)
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
_, _ = w.Write([]byte("OK"))
}))
defer server.Close()

Expand Down
Loading