(method, path, headerString, body string, failOnHTTPError bool)
| 33 | } |
| 34 | |
| 35 | func (repo CloudControllerCurlRepository) Request(method, path, headerString, body string, failOnHTTPError bool) (resHeaders, resBody string, err error) { |
| 36 | url := fmt.Sprintf("%s/%s", repo.config.APIEndpoint(), strings.TrimLeft(path, "/")) |
| 37 | |
| 38 | if method == "" && body != "" { |
| 39 | method = "POST" |
| 40 | } |
| 41 | |
| 42 | req, err := repo.gateway.NewRequest(method, url, repo.config.AccessToken(), strings.NewReader(body)) |
| 43 | if err != nil { |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | err = mergeHeaders(req.HTTPReq.Header, headerString) |
| 48 | if err != nil { |
| 49 | err = fmt.Errorf("%s: %s", T("Error parsing headers"), err.Error()) |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | res, err := repo.gateway.PerformRequest(req) |
| 54 | |
| 55 | if _, ok := err.(errors.HTTPError); ok && !failOnHTTPError { |
| 56 | err = nil |
| 57 | } |
| 58 | |
| 59 | if err != nil { |
| 60 | return |
| 61 | } |
| 62 | defer res.Body.Close() |
| 63 | |
| 64 | headerBytes, _ := httputil.DumpResponse(res, false) |
| 65 | resHeaders = string(headerBytes) |
| 66 | |
| 67 | bytes, err := ioutil.ReadAll(res.Body) |
| 68 | if err != nil { |
| 69 | err = fmt.Errorf("%s: %s", T("Error reading response"), err.Error()) |
| 70 | } |
| 71 | resBody = string(bytes) |
| 72 | |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | func mergeHeaders(destination http.Header, headerString string) (err error) { |
| 77 | headerString = strings.TrimSpace(headerString) |
nothing calls this directly
no test coverage detected