Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/internal/httpdump"
"github.com/containers/image/v5/internal/iolimits"
"github.com/containers/image/v5/internal/multierr"
"github.com/containers/image/v5/internal/set"
Expand Down Expand Up @@ -648,7 +649,7 @@ func (c *dockerClient) makeRequestToResolvedURLOnce(ctx context.Context, method
}
}
logrus.Debugf("%s %s", method, resolvedURL.Redacted())
res, err := c.client.Do(req)
res, err := httpdump.DoRequest(c.client, req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -830,7 +831,7 @@ func (c *dockerClient) getBearerTokenOAuth2(ctx context.Context, challenge chall
authReq.Header.Add("User-Agent", c.userAgent)
authReq.Header.Add("Content-Type", "application/x-www-form-urlencoded")
logrus.Debugf("%s %s", authReq.Method, authReq.URL.Redacted())
res, err := c.client.Do(authReq)
res, err := httpdump.DoRequest(c.client, authReq)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -877,7 +878,7 @@ func (c *dockerClient) getBearerToken(ctx context.Context, challenge challenge,
authReq.Header.Add("User-Agent", c.userAgent)

logrus.Debugf("%s %s", authReq.Method, authReq.URL.Redacted())
res, err := c.client.Do(authReq)
res, err := httpdump.DoRequest(c.client, authReq)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion docker/docker_image_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"sync"

"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/internal/httpdump"
"github.com/containers/image/v5/internal/imagesource/impl"
"github.com/containers/image/v5/internal/imagesource/stubs"
"github.com/containers/image/v5/internal/iolimits"
Expand Down Expand Up @@ -562,7 +563,7 @@ func (s *dockerImageSource) getOneSignature(ctx context.Context, sigURL *url.URL
if err != nil {
return nil, false, err
}
res, err := s.c.client.Do(req)
res, err := httpdump.DoRequest(s.c.client, req)
if err != nil {
return nil, false, err
}
Expand Down
31 changes: 31 additions & 0 deletions internal/httpdump/dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package httpdump

import (
"net/http"
"net/http/httputil"

"github.com/sirupsen/logrus"
)

// DoRequest (c, req) is the same as c.Do(req), but it may log the
// request and response at logrus trace level.
func DoRequest(c *http.Client, req *http.Request) (*http.Response, error) {
if logrus.IsLevelEnabled(logrus.TraceLevel) {
if dro, err := httputil.DumpRequestOut(req, false); err != nil {
logrus.Tracef("===Can not log HTTP request: %v", err)
} else {
logrus.Tracef("===REQ===\n%s\n===REQ===\n", dro)
}
}
res, err := c.Do(req)
if logrus.IsLevelEnabled(logrus.TraceLevel) {
if err != nil {
logrus.Tracef("===RES error: %v", err)
} else if dr, err := httputil.DumpResponse(res, false); err != nil {
logrus.Tracef("===Can not log HTTP response: %v", err)
} else {
logrus.Tracef("===RES===\n%s\n===RES===\n", dr)
}
}
return res, err
}
3 changes: 2 additions & 1 deletion oci/layout/oci_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strconv"

"github.com/containers/image/v5/internal/httpdump"
"github.com/containers/image/v5/internal/imagesource/impl"
"github.com/containers/image/v5/internal/imagesource/stubs"
"github.com/containers/image/v5/internal/manifest"
Expand Down Expand Up @@ -186,7 +187,7 @@ func (s *ociImageSource) getExternalBlob(ctx context.Context, urls []string) (io
continue
}

resp, err := s.client.Do(req)
resp, err := httpdump.DoRequest(s.client, req)
if err != nil {
errWrap = fmt.Errorf("fetching %q failed %s: %w", u, err.Error(), errWrap)
continue
Expand Down
7 changes: 3 additions & 4 deletions openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/internal/httpdump"
"github.com/containers/image/v5/internal/iolimits"
"github.com/containers/image/v5/version"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -95,7 +96,7 @@ func (c *openshiftClient) doRequest(ctx context.Context, method, path string, re
}

logrus.Debugf("%s %s", method, requestURL.Redacted())
res, err := c.httpClient.Do(req)
res, err := httpdump.DoRequest(c.httpClient, req)
if err != nil {
return nil, err
}
Expand All @@ -104,9 +105,7 @@ func (c *openshiftClient) doRequest(ctx context.Context, method, path string, re
if err != nil {
return nil, err
}
logrus.Debugf("Got body: %s", body)
// FIXME: Just throwing this useful information away only to try to guess later...
logrus.Debugf("Got content-type: %s", res.Header.Get("Content-Type"))
// FIXME: Just throwing Content-Type away only to try to guess later...

var status status
statusValid := false
Expand Down