Skip to content

Commit c04e604

Browse files
authored
Merge pull request #29 from bbkane/JosiahBradley/issue28
Reallow HTTP2 to prevent 403 error on API calls with golang >= 1.21
2 parents a74dc6d + 54663c4 commit c04e604

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

grab.go

+7-26
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ func getTopPosts(ctx context.Context, timeout time.Duration, logger *logos.Logge
149149

150150
ua := runtime.GOOS + ":" + "grabbit" + ":" + version + " (go.bbkane.com/grabbit)"
151151

152-
// The reddit API does not like HTTP/2
153-
// Per https://pkg.go.dev/net/http?utm_source=gopls#pkg-overview ,
154-
// I'm copying http.DefaultTransport and replacing the HTTP/2 stuff
155152
transport := &http.Transport{
156153
Dial: nil,
157154
DialTLSContext: nil,
@@ -169,29 +166,13 @@ func getTopPosts(ctx context.Context, timeout time.Duration, logger *logos.Logge
169166
ReadBufferSize: 0,
170167
Proxy: http.ProxyFromEnvironment,
171168
OnProxyConnectResponse: nil,
172-
DialContext: (&net.Dialer{
173-
Timeout: 30 * time.Second,
174-
KeepAlive: 30 * time.Second,
175-
Deadline: time.Time{},
176-
LocalAddr: nil,
177-
DualStack: false,
178-
FallbackDelay: 0,
179-
Resolver: nil,
180-
Cancel: nil,
181-
Control: nil,
182-
ControlContext: nil,
183-
}).DialContext,
184-
185-
// change from default
186-
ForceAttemptHTTP2: false,
187-
188-
MaxIdleConns: 100,
189-
IdleConnTimeout: 90 * time.Second,
190-
TLSHandshakeTimeout: 10 * time.Second,
191-
192-
// use an empty map instead of nil per the link above
193-
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
194-
169+
DialContext: nil,
170+
// https://www.reddit.com/r/redditdev/comments/uncu00/comment/i8gyfmx/
171+
ForceAttemptHTTP2: true,
172+
MaxIdleConns: 100,
173+
IdleConnTimeout: 90 * time.Second,
174+
TLSHandshakeTimeout: 10 * time.Second,
175+
TLSNextProto: nil,
195176
ExpectContinueTimeout: 1 * time.Second,
196177
}
197178

0 commit comments

Comments
 (0)