~julian-edwards/gwacl/licence-readme-etc

« back to all changes in this revision

Viewing changes to x509dispatcher.go

  • Committer: Tarmac
  • Author(s): Gavin Panella
  • Date: 2013-07-25 22:02:41 UTC
  • mfrom: (192.2.26 remove-role-endpoints)
  • Revision ID: tarmac-20130725220241-3h1spquba0z4x8tk
[r=julian-edwards,rvb][bug=][author=allenap] New method RemoveRoleEndpoints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    ContentType string
16
16
}
17
17
 
18
 
// Print debugging output.
19
 
var verbose = false
20
 
 
21
 
func SetVerbose(newVerbose bool) {
22
 
    verbose = newVerbose
23
 
}
24
 
 
25
18
// newX509RequestGET initializes an X509Request for a GET.  You may still need
26
19
// to set further values.
27
20
func newX509RequestGET(url, apiVersion string) *X509Request {
68
61
type x509Response struct {
69
62
    StatusCode int
70
63
    // TODO: What exactly do we get back?  How will we know its encoding?
71
 
    Body      []byte
72
 
    RawHeader []byte
73
 
    Header    http.Header
 
64
    Body   []byte
 
65
    Header http.Header
74
66
}
75
67
 
76
68
func newX509Response() *x509Response {
77
69
    return &x509Response{
78
 
        Body:      make([]byte, 0),
79
 
        RawHeader: make([]byte, 0),
 
70
        Body: make([]byte, 0),
80
71
    }
81
72
}
82
73
 
83
74
func performX509Request(session *x509Session, request *X509Request) (*x509Response, error) {
84
 
    if verbose {
85
 
        Debug("Performing request")
86
 
        Debug("Request url: " + request.URL)
87
 
        Debug("Request method: " + request.Method)
88
 
        Debugf("Request body: %s\n", request.Payload)
 
75
    Debugf("Request: %s %s", request.Method, request.URL)
 
76
    if len(request.Payload) > 0 {
 
77
        Debugf("Request body:\n%s", request.Payload)
89
78
    }
90
79
 
91
80
    bodyReader := ioutil.NopCloser(bytes.NewReader(request.Payload))
107
96
        return nil, err
108
97
    }
109
98
    response.Header = httpResponse.Header
110
 
    if verbose {
111
 
        Debug("Got response")
112
 
        Debugf("Response status: %d\n", response.StatusCode)
113
 
        Debugf("Response headers: %s\n", response.RawHeader)
114
 
        Debugf("Response body: %s\n", response.Body)
115
 
    }
 
99
 
 
100
    Debugf("Response: %d %s", response.StatusCode, http.StatusText(response.StatusCode))
 
101
    if response.Header != nil {
 
102
        buf := bytes.Buffer{}
 
103
        response.Header.Write(&buf)
 
104
        Debugf("Response headers:\n%s", buf.String())
 
105
    }
 
106
    if len(response.Body) > 0 {
 
107
        Debugf("Response body:\n%s", response.Body)
 
108
    }
 
109
 
116
110
    return response, nil
117
111
}