Skip to content

Commit

Permalink
chore(registry): adopt commit suggestion for registry-plugin/main.go
Browse files Browse the repository at this point in the history
Co-authored-by: Juan Vallés <3977183+jvallesm@users.noreply.github.com>
  • Loading branch information
pinglin and jvallesm committed Mar 15, 2024
1 parent aa7ec89 commit 425aedf
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions registry-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ func (r registerer) registerHandlers(_ context.Context, extra map[string]interfa

return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {

if !strings.Contains(req.URL.Path, "/v2/") {
h.ServeHTTP(w, req)
}

// If the URL path contains /v2/, indicating a request to Distribution Registry HTTP API V2,
// the traffic is hijacked and directed to the registry
if strings.Contains(req.URL.Path, "/v2/") {
req.URL.Scheme = "http"
req.URL.Host = hostport
req.RequestURI = ""

resp, err := http.DefaultClient.Do(req)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
req.URL.Scheme = "http"
req.URL.Host = hostport
req.RequestURI = ""

resp, err := http.DefaultClient.Do(req)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Copy headers, status codes, and body from the backend to the response writer
for k, hs := range resp.Header {
for _, h := range hs {
w.Header().Add(k, h)
}
// Copy headers, status codes, and body from the backend to the response writer
for k, hs := range resp.Header {
for _, h := range hs {
w.Header().Add(k, h)
}
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
resp.Body.Close()
} else {
h.ServeHTTP(w, req)
}
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
resp.Body.Close()

}), nil
}
Expand Down

0 comments on commit 425aedf

Please sign in to comment.