Skip to content

Commit

Permalink
WIP: Dump HTTP operations
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Mar 4, 2017
1 parent 1d7e25b commit 4a5b2b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"net"
"net/http"
"net/http/httputil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -248,10 +249,14 @@ func (c *dockerClient) makeRequestToResolvedURL(method, url string, headers map[
}
}
logrus.Debugf("%s %s", method, url)
dro, _ := httputil.DumpRequestOut(req, false)
logrus.Errorf("===REQ===\n%s\n===REQ===\n", dro)
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
dr, _ := httputil.DumpResponse(res, false)
logrus.Errorf("===RES===\n%s\n===RES===\n", dr)
return res, nil
}

Expand Down Expand Up @@ -313,10 +318,14 @@ func (c *dockerClient) getBearerToken(realm, service, scope string) (*bearerToke
// TODO(runcom): insecure for now to contact the external token service
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client := &http.Client{Transport: tr}
dro, _ := httputil.DumpRequestOut(authReq, false)
logrus.Errorf("===REQ===\n%s\n===REQ===\n", dro)
res, err := client.Do(authReq)
if err != nil {
return nil, err
}
dr, _ := httputil.DumpResponse(res, false)
logrus.Errorf("===RES===\n%s\n===RES===\n", dr)
defer res.Body.Close()
switch res.StatusCode {
case http.StatusUnauthorized:
Expand Down
11 changes: 10 additions & 1 deletion docker/docker_image_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"mime"
"net/http"
"net/http/httputil"
"net/url"
"os"
"strconv"
Expand Down Expand Up @@ -239,11 +240,19 @@ func (s *dockerImageSource) getOneSignature(url *url.URL) (signature []byte, mis
return sig, false, nil

case "http", "https":
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, false, err
}
logrus.Debugf("GET %s", url)
res, err := s.c.client.Get(url.String())
dro, _ := httputil.DumpRequestOut(req, false)
logrus.Errorf("===REQ===\n%s\n===REQ===\n", dro)
res, err := s.c.client.Do(req)
if err != nil {
return nil, false, err
}
dr, _ := httputil.DumpResponse(res, false)
logrus.Errorf("===RES===\n%s\n===RES===\n", dr)
defer res.Body.Close()
if res.StatusCode == http.StatusNotFound {
return nil, true, nil
Expand Down
9 changes: 6 additions & 3 deletions openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"net/http"
"net/http/httputil"
"net/url"
"strings"

Expand Down Expand Up @@ -95,18 +96,20 @@ func (c *openshiftClient) doRequest(method, path string, requestBody []byte) ([]
}

logrus.Debugf("%s %s", method, url)
dro, _ := httputil.DumpRequestOut(req, false)
logrus.Errorf("===REQ===\n%s\n===REQ===\n", dro)
res, err := c.httpClient.Do(req)
if err != nil {
return nil, err
}
dr, _ := httputil.DumpResponse(res, false)
logrus.Errorf("===RES===\n%s\n===RES===\n", dr)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
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

0 comments on commit 4a5b2b5

Please sign in to comment.