fork of go-git with some jj specific features
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

transport: http, fix services redirecting only info/refs

Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>

+56 -10
+26 -8
plumbing/transport/http/common.go
··· 6 6 "fmt" 7 7 "net/http" 8 8 "strconv" 9 + "strings" 9 10 10 11 "gopkg.in/src-d/go-git.v4/plumbing" 11 12 "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp" ··· 28 29 req.Header.Add("Content-Length", strconv.Itoa(content.Len())) 29 30 } 30 31 32 + const infoRefsPath = "/info/refs" 33 + 31 34 func advertisedReferences(s *session, serviceName string) (*packp.AdvRefs, error) { 32 35 url := fmt.Sprintf( 33 - "%s/info/refs?service=%s", 34 - s.endpoint.String(), serviceName, 36 + "%s%s?service=%s", 37 + s.endpoint.String(), infoRefsPath, serviceName, 35 38 ) 36 39 37 40 req, err := http.NewRequest(http.MethodGet, url, nil) ··· 39 42 return nil, err 40 43 } 41 44 42 - s.applyAuthToRequest(req) 45 + s.ApplyAuthToRequest(req) 43 46 applyHeadersToRequest(req, nil, s.endpoint.Host, serviceName) 44 47 res, err := s.client.Do(req) 45 48 if err != nil { 46 49 return nil, err 47 50 } 48 51 52 + s.ModifyEndpointIfRedirect(res) 49 53 defer ioutil.CheckClose(res.Body, &err) 50 54 51 55 if err := NewErr(res); err != nil { ··· 129 133 return s, nil 130 134 } 131 135 132 - func (*session) Close() error { 133 - return nil 134 - } 135 - 136 - func (s *session) applyAuthToRequest(req *http.Request) { 136 + func (s *session) ApplyAuthToRequest(req *http.Request) { 137 137 if s.auth == nil { 138 138 return 139 139 } 140 140 141 141 s.auth.setAuth(req) 142 + } 143 + 144 + func (s *session) ModifyEndpointIfRedirect(res *http.Response) { 145 + if res.Request == nil { 146 + return 147 + } 148 + 149 + r := res.Request 150 + if !strings.HasSuffix(r.URL.Path, infoRefsPath) { 151 + return 152 + } 153 + 154 + s.endpoint.Protocol = r.URL.Scheme 155 + s.endpoint.Path = r.URL.Path[:len(r.URL.Path)-len(infoRefsPath)] 156 + } 157 + 158 + func (*session) Close() error { 159 + return nil 142 160 } 143 161 144 162 // AuthMethod is concrete implementation of common.AuthMethod for HTTP services
+1 -1
plumbing/transport/http/receive_pack.go
··· 90 90 } 91 91 92 92 applyHeadersToRequest(req, content, s.endpoint.Host, transport.ReceivePackServiceName) 93 - s.applyAuthToRequest(req) 93 + s.ApplyAuthToRequest(req) 94 94 95 95 res, err := s.client.Do(req.WithContext(ctx)) 96 96 if err != nil {
+1 -1
plumbing/transport/http/upload_pack.go
··· 88 88 } 89 89 90 90 applyHeadersToRequest(req, content, s.endpoint.Host, transport.UploadPackServiceName) 91 - s.applyAuthToRequest(req) 91 + s.ApplyAuthToRequest(req) 92 92 93 93 res, err := s.client.Do(req.WithContext(ctx)) 94 94 if err != nil {
+28
plumbing/transport/http/upload_pack_test.go
··· 75 75 76 76 return ep 77 77 } 78 + 79 + func (s *UploadPackSuite) TestAdvertisedReferencesRedirectPath(c *C) { 80 + endpoint, _ := transport.NewEndpoint("https://gitlab.com/gitlab-org/gitter/webapp") 81 + 82 + session, err := s.Client.NewUploadPackSession(endpoint, s.EmptyAuth) 83 + c.Assert(err, IsNil) 84 + 85 + info, err := session.AdvertisedReferences() 86 + c.Assert(err, IsNil) 87 + c.Assert(info, NotNil) 88 + 89 + url := session.(*upSession).endpoint.String() 90 + c.Assert(url, Equals, "https://gitlab.com/gitlab-org/gitter/webapp.git") 91 + } 92 + 93 + func (s *UploadPackSuite) TestAdvertisedReferencesRedirectSchema(c *C) { 94 + endpoint, _ := transport.NewEndpoint("http://github.com/git-fixtures/basic") 95 + 96 + session, err := s.Client.NewUploadPackSession(endpoint, s.EmptyAuth) 97 + c.Assert(err, IsNil) 98 + 99 + info, err := session.AdvertisedReferences() 100 + c.Assert(err, IsNil) 101 + c.Assert(info, NotNil) 102 + 103 + url := session.(*upSession).endpoint.String() 104 + c.Assert(url, Equals, "https://github.com/git-fixtures/basic") 105 + }