Skip to content

Commit 5f9ce26

Browse files
author
Paulo Gomes
authored
Merge pull request #772 from pjbgf/redirect-logging
libgit2: Improve HTTP redirection observability
2 parents d48f4b4 + 23b337f commit 5f9ce26

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/git/libgit2/managed/http.go

+5-3
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)