Skip to content

Commit d698cec

Browse files
author
Prince Rachit Sinha
committed
Fix errors
1 parent c19db5d commit d698cec

File tree

1 file changed

+7
-2
lines changed
  • components/image-builder-bob/pkg/proxy

1 file changed

+7
-2
lines changed

components/image-builder-bob/pkg/proxy/proxy.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
110110
)
111111
for k, v := range proxy.Aliases {
112112
// Docker api request
113-
if strings.HasPrefix(r.URL.Path, "/v2/"+k+"/") || strings.HasPrefix(r.URL.Path, "/"+k+"/") {
113+
if strings.HasPrefix(r.URL.Path, "/v2/"+k+"/") {
114114
repo = &v
115115
alias = k
116116
rewriteDockerAPIURL(r.URL, alias, repo.Repo, repo.Host, repo.Tag)
@@ -202,6 +202,10 @@ func (proxy *Proxy) reverse(alias string) *httputil.ReverseProxy {
202202
//
203203
// @link https://golang.org/src/net/http/httputil/reverseproxy.go
204204
r.Header.Set("X-Forwarded-For", "127.0.0.1")
205+
// if strings.Contains(r.URL.Path, "artifacts-uploads") {
206+
// str := strings.SplitN(r.URL.Path, "/artifacts-uploads", 2)
207+
// r.URL.Path = "/artifacts-uploads" + str[1]
208+
// }
205209
auth, ok := r.Context().Value(authKey).(docker.Authorizer)
206210
if !ok || auth == nil {
207211
return
@@ -218,7 +222,7 @@ func (proxy *Proxy) reverse(alias string) *httputil.ReverseProxy {
218222
// through this proxy.
219223
// We support only relative URLs and not absolute URLs.
220224
if loc := r.Header.Get("Location"); loc != "" {
221-
// We don't want / prefix for relative URL
225+
log.Infof("Original location: %s", loc)
222226
lurl, err := url.Parse(loc)
223227
if err != nil {
224228
return err
@@ -238,6 +242,7 @@ func (proxy *Proxy) reverse(alias string) *httputil.ReverseProxy {
238242
// force scheme to http assuming this proxy never runs as https
239243
lurl.Scheme = proxy.Host.Scheme
240244
r.Header.Set("Location", lurl.String())
245+
log.Infof("Rewrote location: %s", r.Header.Get("Location"))
241246
}
242247

243248
if r.StatusCode == http.StatusBadGateway {

0 commit comments

Comments
 (0)