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 Jan 7, 2017
1 parent ea963d0 commit 8139c71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 17 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 @@ -230,10 +231,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 All @@ -259,10 +264,14 @@ func (c *dockerClient) setupRequestAuth(req *http.Request) error {
// Do not use the body stream, or we couldn't reuse it for the "real" call later.
testReq.Body = nil
testReq.ContentLength = 0
dro, _ := httputil.DumpRequestOut(&testReq, false)
logrus.Errorf("===REQ===\n%s\n===REQ===\n", dro)
res, err := c.client.Do(&testReq)
if err != nil {
return err
}
dr, _ := httputil.DumpResponse(res, false)
logrus.Errorf("===RES===\n%s\n===RES===\n", dr)
chs := parseAuthHeader(res.Header)
// We could end up in this "if" statement if the /v2/ call (during ping)
// returned 401 with a valid WWW-Authenticate=Bearer header.
Expand All @@ -288,10 +297,14 @@ func (c *dockerClient) setupRequestAuth(req *http.Request) error {
testReq2.Body = nil
testReq2.ContentLength = 0
testReq2.SetBasicAuth(c.username, c.password)
dro, _ := httputil.DumpRequestOut(&testReq2, false)
logrus.Errorf("===REQ===\n%s\n===REQ===\n", dro)
res, err := c.client.Do(&testReq2)
if err != nil {
return err
}
dr, _ := httputil.DumpResponse(res, false)
logrus.Errorf("===RES===\n%s\n===RES===\n", dr)
chs = parseAuthHeader(res.Header)
if res.StatusCode != http.StatusUnauthorized || chs == nil || len(chs) == 0 {
// no need for bearer? wtf?
Expand Down Expand Up @@ -340,10 +353,14 @@ func (c *dockerClient) getBearerToken(realm, service, scope string) (string, err
// 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 "", 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
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 @@ -94,18 +95,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 8139c71

Please sign in to comment.