detached 278618d

chore: address code review findings

- Rename shadowed err variable in resolveTargetMetadata
- Lower registry routing log from Info to Debug
- Rename misleading MaxBodySize test
- Clarify limitedReadCloser.Read slice capping
- Fix Go version in h2c transport comment (1.24+)
commit
278618d3ed197a8f4dd70b790b8bf2a035e2dbee
author
brice · · 2026-03-16 00:17 UTC
parent
01ffd59
signature
unsigned
4 files · +10 -9
M internal/adapters/in/http/proxy/forwarder.go +5 -4
@@ -35,7 +35,7 @@ func newAppTransport() *http.Transport {
3535
3636 // newH2CTransport creates a dedicated cleartext HTTP/2 transport for containers
3737 // that opt in via the gordon.proxy.protocol=h2c label.
38-// Uses Go 1.26 native UnencryptedHTTP2 protocol support.
38+// Uses Go 1.24+ native UnencryptedHTTP2 protocol support.
3939 // HTTP/1 is disabled so http:// URLs use HTTP/2 prior-knowledge.
4040 func newH2CTransport() *http.Transport {
4141 var protos http.Protocols
@@ -248,10 +248,11 @@ func (l *limitedReadCloser) Read(p []byte) (int, error) {
248248 }
249249 return 0, fmt.Errorf("response body exceeded maximum size limit")
250250 }
251- if int64(len(p)) > l.remaining {
252- p = p[:l.remaining]
251+ toRead := len(p)
252+ if int64(toRead) > l.remaining {
253+ toRead = int(l.remaining)
253254 }
254- n, err := l.ReadCloser.Read(p)
255+ n, err := l.ReadCloser.Read(p[:toRead])
255256 l.remaining -= int64(n)
256257 return n, err
257258 }
@@ -35,7 +35,7 @@ func newAppTransport() *http.Transport {
35 35
36 // newH2CTransport creates a dedicated cleartext HTTP/2 transport for containers36 // newH2CTransport creates a dedicated cleartext HTTP/2 transport for containers
37 // that opt in via the gordon.proxy.protocol=h2c label.37 // that opt in via the gordon.proxy.protocol=h2c label.
38-// Uses Go 1.26 native UnencryptedHTTP2 protocol support.38+// Uses Go 1.24+ native UnencryptedHTTP2 protocol support.
39 // HTTP/1 is disabled so http:// URLs use HTTP/2 prior-knowledge.39 // HTTP/1 is disabled so http:// URLs use HTTP/2 prior-knowledge.
40 func newH2CTransport() *http.Transport {40 func newH2CTransport() *http.Transport {
41 var protos http.Protocols41 var protos http.Protocols
@@ -248,10 +248,11 @@ func (l *limitedReadCloser) Read(p []byte) (int, error) {
248 }248 }
249 return 0, fmt.Errorf("response body exceeded maximum size limit")249 return 0, fmt.Errorf("response body exceeded maximum size limit")
250 }250 }
251- if int64(len(p)) > l.remaining {251+ toRead := len(p)
252- p = p[:l.remaining]252+ if int64(toRead) > l.remaining {
253+ toRead = int(l.remaining)
253 }254 }
254- n, err := l.ReadCloser.Read(p)255+ n, err := l.ReadCloser.Read(p[:toRead])
255 l.remaining -= int64(n)256 l.remaining -= int64(n)
256 return n, err257 return n, err
257 }258 }
M internal/adapters/in/http/proxy/handler.go +1 -1
@@ -68,7 +68,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
6868
6969 // Check if this is the registry domain
7070 if h.proxySvc.IsRegistryDomain(r.Host) {
71- log.Info().Msg("routing request to registry")
71+ log.Debug().Msg("routing request to registry")
7272 h.forwardToRegistry(w, r, cfg.RegistryPort)
7373 return
7474 }
@@ -68,7 +68,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
68 68
69 // Check if this is the registry domain69 // Check if this is the registry domain
70 if h.proxySvc.IsRegistryDomain(r.Host) {70 if h.proxySvc.IsRegistryDomain(r.Host) {
71- log.Info().Msg("routing request to registry")71+ log.Debug().Msg("routing request to registry")
72 h.forwardToRegistry(w, r, cfg.RegistryPort)72 h.forwardToRegistry(w, r, cfg.RegistryPort)
73 return73 return
74 }74 }
M internal/adapters/in/http/proxy/handler_test.go +1 -1
@@ -110,7 +110,7 @@ func TestHandler_ProxiesToTarget(t *testing.T) {
110110 assert.Equal(t, "ok", w.Body.String())
111111 }
112112
113-func TestHandler_MaxBodySize_Applied(t *testing.T) {
113+func TestHandler_ReadsMaxBodySizeConfig(t *testing.T) {
114114 proxySvc := inmocks.NewMockProxyService(t)
115115
116116 proxySvc.EXPECT().ProxyConfig().Return(in.ProxyServiceConfig{
@@ -110,7 +110,7 @@ func TestHandler_ProxiesToTarget(t *testing.T) {
110 assert.Equal(t, "ok", w.Body.String())110 assert.Equal(t, "ok", w.Body.String())
111 }111 }
112 112
113-func TestHandler_MaxBodySize_Applied(t *testing.T) {113+func TestHandler_ReadsMaxBodySizeConfig(t *testing.T) {
114 proxySvc := inmocks.NewMockProxyService(t)114 proxySvc := inmocks.NewMockProxyService(t)
115 115
116 proxySvc.EXPECT().ProxyConfig().Return(in.ProxyServiceConfig{116 proxySvc.EXPECT().ProxyConfig().Return(in.ProxyServiceConfig{
M internal/usecase/proxy/target_metadata.go +3 -3
@@ -46,9 +46,9 @@ func (s *Service) resolveTargetMetadata(ctx context.Context, imageRef string) (T
4646 }
4747
4848 if port == 0 {
49- exposedPorts, err := s.runtime.GetImageExposedPorts(ctx, imageRef)
50- if err != nil {
51- return TargetMetadata{}, err
49+ exposedPorts, portsErr := s.runtime.GetImageExposedPorts(ctx, imageRef)
50+ if portsErr != nil {
51+ return TargetMetadata{}, portsErr
5252 }
5353 if len(exposedPorts) == 0 {
5454 return TargetMetadata{}, fmt.Errorf("no exposed ports found for image %s", imageRef)
@@ -46,9 +46,9 @@ func (s *Service) resolveTargetMetadata(ctx context.Context, imageRef string) (T
46 }46 }
47 47
48 if port == 0 {48 if port == 0 {
49- exposedPorts, err := s.runtime.GetImageExposedPorts(ctx, imageRef)49+ exposedPorts, portsErr := s.runtime.GetImageExposedPorts(ctx, imageRef)
50- if err != nil {50+ if portsErr != nil {
51- return TargetMetadata{}, err51+ return TargetMetadata{}, portsErr
52 }52 }
53 if len(exposedPorts) == 0 {53 if len(exposedPorts) == 0 {
54 return TargetMetadata{}, fmt.Errorf("no exposed ports found for image %s", imageRef)54 return TargetMetadata{}, fmt.Errorf("no exposed ports found for image %s", imageRef)

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close