Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit a77b281

Browse files
committed
Fix host redirect handling
If you try to clone from a url that redirects to another host e.g. `example.com/repo` -> `github.com/org/repo.git`, it results in a redirect to `example.com/org/repo.git` because ModifyEndpointIfRedirect only takes into account the scheme and path. Signed-off-by: DisposaBoy <[email protected]>
1 parent 87cc819 commit a77b281

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

plumbing/transport/http/common.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package http
44
import (
55
"bytes"
66
"fmt"
7+
"net"
78
"net/http"
89
"strconv"
910
"strings"
@@ -151,7 +152,14 @@ func (s *session) ModifyEndpointIfRedirect(res *http.Response) {
151152
return
152153
}
153154

155+
host, port, err := net.SplitHostPort(r.URL.Host)
156+
if err != nil {
157+
host = r.URL.Host
158+
}
159+
154160
s.endpoint.Protocol = r.URL.Scheme
161+
s.endpoint.Host = host
162+
s.endpoint.Port, _ = strconv.Atoi(port)
155163
s.endpoint.Path = r.URL.Path[:len(r.URL.Path)-len(infoRefsPath)]
156164
}
157165

0 commit comments

Comments
 (0)