Skip to content

Commit 23b337f

Browse files
author
Paulo Gomes
committed
libgit2: Improve HTTP redirection observability
Git repositories may be redirected to different URLs when they are accessed via HTTP. The two most obvious scenarios are from HTTP to HTTPS and when the .git suffix is missing. By improving the logging on this process users can identify changes required to their GitRepository objects. Signed-off-by: Paulo Gomes <[email protected]>
1 parent d48f4b4 commit 23b337f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/git/libgit2/managed/http.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (t *httpSmartSubtransport) Action(transportOptionsURL string, action git2go
165165
// Therefore, on the initial GET operation we update the target URL to include the
166166
// new target, so the subsequent actions include the correct target URL.
167167
// Example of this is trying to access a Git repository without the .git suffix.
168-
if req.Response != nil && req.Response.StatusCode == http.StatusMovedPermanently {
168+
if req.Response != nil {
169169
if newURL, err := req.Response.Location(); err == nil && newURL != nil {
170170
if strings.EqualFold(newURL.Host, req.URL.Host) && strings.EqualFold(newURL.Port(), req.URL.Port()) {
171171
opts, _ := getTransportOptions(transportOptionsURL)
@@ -175,6 +175,9 @@ func (t *httpSmartSubtransport) Action(transportOptionsURL string, action git2go
175175

176176
opts.TargetURL = trimActionSuffix(newURL.String())
177177
AddTransportOptions(transportOptionsURL, *opts)
178+
179+
debugLog.Info("[http]: server responded with redirect",
180+
"newURL", opts.TargetURL, "StatusCode", req.Response.StatusCode)
178181
}
179182
}
180183
}
@@ -419,7 +422,6 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
419422
return err
420423
}
421424

422-
traceLog.Info("[http]: POST redirect", "URL", self.req.URL)
423425
continue
424426
}
425427

@@ -435,7 +437,7 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
435437
return err
436438
}
437439

438-
return fmt.Errorf("Unhandled HTTP error %s", resp.Status)
440+
return fmt.Errorf("unhandled HTTP error %s", resp.Status)
439441
}
440442

441443
self.resp = resp

0 commit comments

Comments
 (0)