@@ -50,7 +50,7 @@ func ProxyRequestHandler(p *httputil.ReverseProxy) func(http.ResponseWriter, *ht
5050
5151func ProxyResponseHandler () func (* http.Response ) error {
5252 return func (r * http.Response ) error {
53- log .Printf ("Received response from %s" , r .Request .URL .String ())
53+ log .Printf ("Received %d response from %s" , r . StatusCode , r .Request .URL .String ())
5454 log .Printf ("RES: %s \" %s\" %d \" %s\" \" %s\" " , r .Request .RemoteAddr , r .Request .Method , r .StatusCode , r .Request .RequestURI , r .Request .UserAgent ())
5555
5656 contentType := r .Header .Get ("Content-Type" )
@@ -67,11 +67,15 @@ func ProxyResponseHandler() func(*http.Response) error {
6767 if r .StatusCode == 301 || r .StatusCode == 302 {
6868 location , _ := r .Location ()
6969
70- location .Host = originalUrl .Host
71- location .Scheme = originalUrl .Scheme
72- location .Path = strings .Replace (location .Path , u .Path , "" , 1 )
70+ // Only attempt to rewrite the location if the host matches the CodeArtifact host
71+ // Otherwise leave the original location intact (e.g a redirect to a S3 presigned URL)
72+ if location .Host == u .Host {
73+ location .Host = originalUrl .Host
74+ location .Scheme = originalUrl .Scheme
75+ location .Path = strings .Replace (location .Path , u .Path , "" , 1 )
7376
74- r .Header .Set ("Location" , location .String ())
77+ r .Header .Set ("Location" , location .String ())
78+ }
7579 }
7680
7781 // Do some quick fixes to the HTTP response for NPM install requests
0 commit comments