refactor: extract shared HTTP timeouts#1022
Conversation
Centralize the five HTTP-client timeouts called out in floatpane#989 behind named constants in a new internal/httpclient package. Replaces magic-number literals at plugin/http.go:13, plugins/embed.go:25/56, view/html.go:300, cli/install.go:25, and main.go:67 with httpclient.PluginCallTimeout / RegistryFetchTimeout / RemoteImageTimeout / InstallTimeout / UpdateCheckTimeout. main.go's 5-redirect cap is preserved via the new NewWithRedirectCap helper. No behavior change. Same timeouts, same redirect policy, same call-site patterns; just no more magic numbers. Closes floatpane#989
floatpanebot
left a comment
There was a problem hiding this comment.
Hi @mvanhorn! Please fix the following issues with your PR:
- Title: Is too long (69 characters). The PR title must be strictly under 40 characters.
- Body: Missing the
## What?or## Why?headings required by the PR template.
Formatting issues have been resolved. Thank you!
|
Fixed: title shortened to 38 chars, body now uses |
|
@LeaWhoCodes check this out. |
|
Appreciate the merge @LeaWhoCodes. Centralizing the five HTTP timeouts behind named constants in |
|
Thanks @LeaWhoCodes. Centralizing those five HTTP timeouts into one internal/httpclient package was overdue, and now they are tunable from one place instead of scattered literals. |
|
Cheers @LeaWhoCodes, thanks for landing this. Centralizing the five HTTP timeouts in internal/httpclient with named constants per callsite should keep #989 from coming back. |
What?
Centralizes the five HTTP-client timeouts that #989 called out. New
internal/httpclientpackage owns named constants for each call site (PluginCallTimeout,RegistryFetchTimeout,RemoteImageTimeout,InstallTimeout,UpdateCheckTimeout) plus a thinNew(timeout)/NewWithRedirectCap(timeout, max)factory pair. Each of the five sites listed in the issue now references the constant instead of inlining a magic duration.Why?
Issue #989 lists
plugin/http.go:13(10s),plugins/embed.go:25/56(10s × 2),view/html.go:300(5s),cli/install.go:25(30s), andmain.go:67(30s) as five different HTTP timeout literals across the codebase with no central knob. The issue offers two acceptable approaches: a configurable client factory, or "at minimum, extract timeout constants to a shared config." This PR takes the minimum-scope path so the call-site behavior is unchanged: same five timeouts, same intent (Lua plugin calls vs registry fetches vs inline image fetches vs CLI install vs update check), but no more grepping fortime.Secondto find them.main.go's 5-redirect cap is the only non-trivial bit — it has a customCheckRedirectthat the other clients explicitly don't want. TheNewWithRedirectCaphelper preserves that policy without inlining the literal5or the redirectfmt.Errorfagain.Changes
internal/httpclient/httpclient.go— five named timeout constants with site-attributing doc comments;New(timeout)andNewWithRedirectCap(timeout, maxRedirects)factories.internal/httpclient/httpclient_test.go— unit tests for the constants, the basic factory, the redirect-cap factory (both via directCheckRedirectinvocation and an end-to-endhttptest.Serverredirect-loop check).plugin/http.go— drops the localhttpTimeoutconst and thetimeimport; switches the package-levelhttpClienttohttpclient.New(httpclient.PluginCallTimeout).plugins/embed.go— replaces both&http.Client{Timeout: 10 * time.Second}literals withhttpclient.New(httpclient.RegistryFetchTimeout).view/html.go— replaces the inline 5-second image client withhttpclient.New(httpclient.RemoteImageTimeout).cli/install.go— replaces the inline 30-second install client withhttpclient.New(httpclient.InstallTimeout).main.go— replaces the package-level redirect-capped client literal withhttpclient.NewWithRedirectCap(httpclient.UpdateCheckTimeout, 5). The5and the "stopped after N redirects" message now live exactly once, in the helper.Testing
go build ./...clean.go vet ./...clean (the existingclibOFF_MAXmacro warning is pre-existing and present onupstream/master).go test ./internal/httpclient/...passes (3 tests including a live-server redirect-cap check).go test ./plugin/... ./plugins/... ./view/... ./cli/...passes — existing package tests untouched.Closes #989
This contribution was developed with AI assistance (Codex).