Skip to content

Commit fa49968

Browse files
committed
rename from jttp to gttp
1 parent 94e7b03 commit fa49968

25 files changed

Lines changed: 108 additions & 73 deletions

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# jttp
1+
# gttp
22

3-
[![ci](https://github.com/jcalabro/jttp/actions/workflows/ci.yaml/badge.svg)](https://github.com/jcalabro/jttp/actions/workflows/ci.yaml)
4-
[![Go Reference](https://pkg.go.dev/badge/github.com/jcalabro/jttp.svg)](https://pkg.go.dev/github.com/jcalabro/jttp)
3+
[![ci](https://github.com/bluesky-social/gttp/actions/workflows/ci.yaml/badge.svg)](https://github.com/bluesky-social/gttp/actions/workflows/ci.yaml)
4+
[![Go Reference](https://pkg.go.dev/badge/github.com/bluesky-social/gttp.svg)](https://pkg.go.dev/github.com/bluesky-social/gttp)
55

6-
A robust HTTP client for Go with good defaults and tunable behavior.
6+
A robust HTTP client for Go with good defaults and tunable behavior. Called `gttp` because it's a "go http" client library.
77

8-
`jttp.New()` returns a standard `*http.Client` with sensible timeouts,
8+
`gttp.New()` returns a standard `*http.Client` with sensible timeouts,
99
connection pooling, retry logic, and safety guards built in.
1010

1111
## Features
@@ -25,17 +25,17 @@ connection pooling, retry logic, and safety guards built in.
2525

2626
```go
2727
// Use the defaults:
28-
client := jttp.New()
28+
client := gttp.New()
2929
resp, err := client.Get("https://example.com")
3030

3131
// Tune for your environment:
32-
client := jttp.New(
33-
jttp.WithTimeout(10 * time.Second),
34-
jttp.WithRetries(5),
35-
jttp.WithIdleTimeout(10 * time.Second),
36-
jttp.WithMaxResponseBodyBytes(100 << 20),
37-
jttp.WithStrictSSRFProtection(),
32+
client := gttp.New(
33+
gttp.WithTimeout(10 * time.Second),
34+
gttp.WithRetries(5),
35+
gttp.WithIdleTimeout(10 * time.Second),
36+
gttp.WithMaxResponseBodyBytes(100 << 20),
37+
gttp.WithStrictSSRFProtection(),
3838
)
3939
```
4040

41-
See [godoc](https://pkg.go.dev/github.com/jcalabro/jttp) for the full option list.
41+
See [godoc](https://pkg.go.dev/github.com/bluesky-social/gttp) for the full option list.

errors.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
1-
package jttp
1+
package gttp
22

33
import "errors"
44

5-
// Sentinel errors returned by jttp. Callers can use errors.Is to distinguish
5+
// Sentinel errors returned by gttp. Callers can use errors.Is to distinguish
66
// them. All are wrapped with %w when returned, so the underlying cause (if
77
// any) remains reachable via errors.Unwrap / errors.As / errors.AsType.
88
var (
99
// ErrBodyTooLarge is returned when a request body exceeds the retry
1010
// buffer limit (see WithMaxRetryBodyBytes) and the body does not
1111
// already provide a GetBody function for rewinding.
12-
ErrBodyTooLarge = errors.New("jttp: request body exceeds retry buffer limit")
12+
ErrBodyTooLarge = errors.New("gttp: request body exceeds retry buffer limit")
1313

1414
// ErrBodyRead is returned when reading the request body into the retry
1515
// buffer fails.
16-
ErrBodyRead = errors.New("jttp: reading request body for retry")
16+
ErrBodyRead = errors.New("gttp: reading request body for retry")
1717

1818
// ErrBodyClose is returned when closing the original request body (after
1919
// buffering it for retry) fails.
20-
ErrBodyClose = errors.New("jttp: closing request body")
20+
ErrBodyClose = errors.New("gttp: closing request body")
2121

2222
// ErrBodyRewind is returned when rewinding the request body between
2323
// retry attempts fails (req.GetBody returned an error).
24-
ErrBodyRewind = errors.New("jttp: rewinding request body")
24+
ErrBodyRewind = errors.New("gttp: rewinding request body")
2525

2626
// ErrTooManyRedirects is returned when the redirect chain exceeds the
2727
// configured maximum (see WithRedirectPolicy).
28-
ErrTooManyRedirects = errors.New("jttp: too many redirects")
28+
ErrTooManyRedirects = errors.New("gttp: too many redirects")
2929

3030
// ErrBodyIdleTimeout is returned when a response body read or a request
3131
// body write stalls for longer than the configured idle timeout
3232
// (see WithIdleTimeout).
33-
ErrBodyIdleTimeout = errors.New("jttp: body idle timeout")
33+
ErrBodyIdleTimeout = errors.New("gttp: body idle timeout")
3434

3535
// ErrBodyTransferTooSlow is returned when the rolling average transfer
3636
// rate of the response body falls below the configured floor
3737
// (see WithMinTransferRate).
38-
ErrBodyTransferTooSlow = errors.New("jttp: body transfer rate below minimum")
38+
ErrBodyTransferTooSlow = errors.New("gttp: body transfer rate below minimum")
3939

4040
// ErrResponseTooLarge is returned when the decompressed response body
4141
// exceeds the configured maximum size (see WithMaxResponseBodyBytes).
42-
ErrResponseTooLarge = errors.New("jttp: response body exceeds max size")
42+
ErrResponseTooLarge = errors.New("gttp: response body exceeds max size")
4343

4444
// ErrDecompressionBomb is returned when the ratio of decompressed to
4545
// compressed bytes exceeds the configured maximum
4646
// (see WithMaxCompressionRatio).
47-
ErrDecompressionBomb = errors.New("jttp: decompression ratio exceeded")
47+
ErrDecompressionBomb = errors.New("gttp: decompression ratio exceeded")
4848

4949
// ErrRedirectLoop is returned when a redirect would revisit a URL
5050
// already seen in the current chain.
51-
ErrRedirectLoop = errors.New("jttp: redirect loop detected")
51+
ErrRedirectLoop = errors.New("gttp: redirect loop detected")
5252

5353
// ErrSchemeDowngrade is returned when a redirect would move from https
5454
// to http without WithAllowSchemeDowngrade.
55-
ErrSchemeDowngrade = errors.New("jttp: redirect downgrades scheme https to http")
55+
ErrSchemeDowngrade = errors.New("gttp: redirect downgrades scheme https to http")
5656

5757
// ErrBlockedByIPPolicy is returned when a redirect target's resolved IP
5858
// falls within one of the default-blocked ranges (private, loopback,
5959
// link-local, multicast, unique-local v6, CGNAT, NAT64, or IMDS addresses).
60-
ErrBlockedByIPPolicy = errors.New("jttp: target resolves to blocked IP range")
60+
ErrBlockedByIPPolicy = errors.New("gttp: target resolves to blocked IP range")
6161
)

errors_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jttp
1+
package gttp
22

33
import (
44
"context"
@@ -107,3 +107,24 @@ func TestTier1SentinelsDefined(t *testing.T) {
107107
}
108108
}
109109
}
110+
111+
func TestSentinelErrorPrefix(t *testing.T) {
112+
for _, err := range []error{
113+
ErrBodyTooLarge,
114+
ErrBodyRead,
115+
ErrBodyClose,
116+
ErrBodyRewind,
117+
ErrTooManyRedirects,
118+
ErrBodyIdleTimeout,
119+
ErrBodyTransferTooSlow,
120+
ErrResponseTooLarge,
121+
ErrDecompressionBomb,
122+
ErrRedirectLoop,
123+
ErrSchemeDowngrade,
124+
ErrBlockedByIPPolicy,
125+
} {
126+
if !strings.HasPrefix(err.Error(), "gttp: ") {
127+
t.Errorf("sentinel error %q does not have gttp prefix", err)
128+
}
129+
}
130+
}

gate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jttp
1+
package gttp
22

33
import (
44
"context"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/jcalabro/jttp
1+
module github.com/bluesky-social/gttp
22

33
go 1.26
44

jttp.go renamed to gttp.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package jttp provides a robust HTTP client with reasonable defaults and
1+
// Package gttp provides a robust HTTP client with reasonable defaults and
22
// tunable behavior.
33
//
44
// The returned *http.Client is fully standard — callers use client.Do,
@@ -17,17 +17,17 @@
1717
//
1818
// Basic usage:
1919
//
20-
// client := jttp.New() // be sure to reuse this single object across multiple requests!
20+
// client := gttp.New() // be sure to reuse this single object across multiple requests!
2121
// resp, err := client.Get("https://example.com")
2222
//
2323
// With options:
2424
//
25-
// client := jttp.New(
26-
// jttp.WithTimeout(10 * time.Second),
27-
// jttp.WithRetries(5),
28-
// jttp.WithAdditionalRetryableStatusCodes(500),
25+
// client := gttp.New(
26+
// gttp.WithTimeout(10 * time.Second),
27+
// gttp.WithRetries(5),
28+
// gttp.WithAdditionalRetryableStatusCodes(500),
2929
// )
30-
package jttp
30+
package gttp
3131

3232
import (
3333
"context"
@@ -288,13 +288,13 @@ func New(opts ...Option) *http.Client {
288288
var err error
289289
h2, err = configureHTTP2(tr, cfg.http2ReadIdleTimeout, cfg.http2PingTimeout)
290290
if err != nil {
291-
panic(fmt.Sprintf("jttp: unexpected error configuring HTTP/2: %v", err))
291+
panic(fmt.Sprintf("gttp: unexpected error configuring HTTP/2: %v", err))
292292
}
293293
}
294294
base = tr
295295
}
296296

297-
// Only a jttp-owned, direct transport can guarantee that the address
297+
// Only a gttp-owned, direct transport can guarantee that the address
298298
// validated by the IP policy is the address actually dialed. Custom
299299
// transports and proxies retain the existing request-time checks.
300300
ipPolicyAtDial := cfg.strictSSRFInitial && cfg.transport == nil && cfg.disableProxy && !cfg.allowPrivateRedirects
@@ -458,7 +458,7 @@ func WithRetryableStatusCodes(codes ...int) Option {
458458
// WithAdditionalRetryableStatusCodes adds status codes to the default retryable set
459459
// without replacing it. For example, to also retry on 500:
460460
//
461-
// jttp.New(jttp.WithAdditionalRetryableStatusCodes(500))
461+
// gttp.New(gttp.WithAdditionalRetryableStatusCodes(500))
462462
func WithAdditionalRetryableStatusCodes(codes ...int) Option {
463463
return func(c *config) {
464464
for _, code := range codes {
@@ -481,7 +481,7 @@ func WithRetryableMethods(methods ...string) Option {
481481
// WithAdditionalRetryableMethods adds HTTP methods to the default retryable set
482482
// without replacing it. For example, to also retry POST and PUT:
483483
//
484-
// jttp.New(jttp.WithAdditionalRetryableMethods("POST", "PUT"))
484+
// gttp.New(gttp.WithAdditionalRetryableMethods("POST", "PUT"))
485485
func WithAdditionalRetryableMethods(methods ...string) Option {
486486
return func(c *config) {
487487
for _, m := range methods {
@@ -530,11 +530,11 @@ func WithRetryObserver(fn func(attempt int, req *http.Request, resp *http.Respon
530530
// timeout, size cap, min-rate) are still applied on top, but note:
531531
//
532532
// The decompression-bomb guard (WithMaxCompressionRatio) is effectively
533-
// disabled when a custom transport is supplied, because jttp can no longer
533+
// disabled when a custom transport is supplied, because gttp can no longer
534534
// control the base transport's DisableCompression setting. The caller's
535535
// transport is presumed to handle Accept-Encoding / gzip decoding itself,
536536
// and once stdlib's default transport auto-decodes, the response arrives
537-
// without a Content-Encoding header for jttp to act on. If you need the
537+
// without a Content-Encoding header for gttp to act on. If you need the
538538
// bomb guard, use the default transport.
539539
func WithTransport(rt http.RoundTripper) Option {
540540
return func(c *config) { c.transport = rt }
@@ -609,7 +609,7 @@ func WithDialKeepAlive(d time.Duration) Option {
609609
//
610610
// WithResolver is likewise ignored in the general case, but not in strict
611611
// direct mode: when WithStrictSSRFProtection and WithNoProxy are set without
612-
// WithAllowPrivateRedirects, jttp resolves the request hostname itself with the
612+
// WithAllowPrivateRedirects, gttp resolves the request hostname itself with the
613613
// configured resolver, validates the full answer set, and calls this function
614614
// only with an already-validated literal IP address. In that mode WithResolver
615615
// controls the validation lookup, and a custom dialer that performs its own
@@ -625,7 +625,7 @@ func WithDialContext(fn func(ctx context.Context, network, address string) (net.
625625
// This is useful for directing DNS queries to a specific server (e.g., 1.1.1.1)
626626
// without replacing the entire dial function. Example:
627627
//
628-
// jttp.New(jttp.WithResolver(&net.Resolver{
628+
// gttp.New(gttp.WithResolver(&net.Resolver{
629629
// PreferGo: true,
630630
// Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
631631
// return (&net.Dialer{}).DialContext(ctx, "udp", "1.1.1.1:53")
@@ -716,9 +716,9 @@ func WithAllowPrivateRedirects() Option {
716716
// attacker-controlled URLs.
717717
//
718718
// Combine this with [WithNoProxy] to bind validation to the actual network
719-
// connection: jttp resolves each hostname once per new connection, validates
719+
// connection: gttp resolves each hostname once per new connection, validates
720720
// every returned address, and dials an approved literal address. With a proxy
721-
// or custom transport, jttp cannot control the target dial and therefore
721+
// or custom transport, gttp cannot control the target dial and therefore
722722
// retains request-time DNS preflight checks instead. The preflight path is
723723
// also retained with [WithAllowPrivateRedirects], whose redirect-specific
724724
// exception cannot be represented safely by a connection-wide dial policy.

jttp_test.go renamed to gttp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jttp
1+
package gttp
22

33
import (
44
"bytes"

guard.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jttp
1+
package gttp
22

33
import (
44
"context"
@@ -135,7 +135,7 @@ func newGuardedBody(inner io.ReadCloser, cfg guardedBodyConfig) (*guardedBody, e
135135
g.compressed = &countingReader{r: inner}
136136
gz, err := gzip.NewReader(g.compressed)
137137
if err != nil {
138-
return nil, fmt.Errorf("jttp: gzip.NewReader: %w", err)
138+
return nil, fmt.Errorf("gttp: gzip.NewReader: %w", err)
139139
}
140140
g.gz = gz
141141
}
@@ -213,7 +213,7 @@ func (g *guardedBody) Close() error {
213213
}
214214

215215
// ctxErr returns the context's cancellation cause if the context is done,
216-
// otherwise nil. If the cause is a jttp sentinel it is returned unwrapped so
216+
// otherwise nil. If the cause is a gttp sentinel it is returned unwrapped so
217217
// errors.Is works naturally at the call site.
218218
func (g *guardedBody) ctxErr() error {
219219
if g.cfg.ctx == nil {

guard_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jttp
1+
package gttp
22

33
import (
44
"bytes"

http2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jttp
1+
package gttp
22

33
import (
44
"net/http"

0 commit comments

Comments
 (0)