MCPcopy Create free account
hub / github.com/cloudfoundry/credhub-cli / request

Method request

credhub/request.go:32–78  ·  view source on GitHub ↗
(client requester, method string, pathStr string, query url.Values, body interface{}, checkServerErr bool)

Source from the content-addressed store, hash-verified

30}
31
32func (ch *CredHub) request(client requester, method string, pathStr string, query url.Values, body interface{}, checkServerErr bool) (*http.Response, error) {
33 u := *ch.baseURL // clone
34 u.Path = pathStr
35 u.RawQuery = query.Encode()
36
37 var req *http.Request
38
39 jsonBody, err := json.Marshal(body)
40 if err != nil {
41 return nil, err
42 }
43
44 if body != nil {
45 req, err = http.NewRequest(method, u.String(), bytes.NewReader(jsonBody))
46 } else {
47 req, err = http.NewRequest(method, u.String(), nil)
48 }
49 if err != nil {
50 return nil, err
51 }
52
53 req.Header.Set("Content-Type", "application/json")
54
55 if os.Getenv("CREDHUB_DEBUG") == "true" {
56 dumpRequest(req)
57 }
58
59 resp, err := client.Do(req)
60 if err != nil {
61 if os.Getenv("CREDHUB_DEBUG") == "true" {
62 fmt.Printf("[DEBUG] %s: %v", "An error occurred during the data request.\n", err)
63 }
64 return resp, err
65 }
66
67 if os.Getenv("CREDHUB_DEBUG") == "true" {
68 dumpResponse(resp)
69 }
70
71 if checkServerErr {
72 if err := ch.checkForServerError(resp); err != nil {
73 return nil, err
74 }
75 }
76
77 return resp, err
78}
79
80func (ch *CredHub) checkForServerError(resp *http.Response) error {
81 if resp.StatusCode < 200 || resp.StatusCode >= 300 {

Callers 2

InfoMethod · 0.95
RequestMethod · 0.95

Calls 5

checkForServerErrorMethod · 0.95
dumpRequestFunction · 0.85
dumpResponseFunction · 0.85
StringMethod · 0.80
DoMethod · 0.65

Tested by

no test coverage detected