MCPcopy Index your code
hub / github.com/cloudfoundry/cli / newHTTPRequest

Method newHTTPRequest

api/cfnetworking/cfnetv1/request.go:37–70  ·  view source on GitHub ↗

newHTTPRequest returns a constructed HTTP.Request with some defaults. Defaults are applied when Request fields are not filled in.

(passedRequest requestOptions)

Source from the content-addressed store, hash-verified

35// newHTTPRequest returns a constructed HTTP.Request with some defaults.
36// Defaults are applied when Request fields are not filled in.
37func (client Client) newHTTPRequest(passedRequest requestOptions) (*cfnetworking.Request, error) {
38 var request *http.Request
39 var err error
40 if passedRequest.URI != "" {
41 request, err = http.NewRequest(
42 passedRequest.Method,
43 fmt.Sprintf("%s%s", client.url, passedRequest.URI),
44 passedRequest.Body,
45 )
46 } else {
47 request, err = client.router.CreateRequest(
48 passedRequest.RequestName,
49 map[string]string(passedRequest.URIParams),
50 passedRequest.Body,
51 )
52 if err == nil {
53 request.URL.RawQuery = passedRequest.Query.Encode()
54 }
55 }
56 if err != nil {
57 return nil, err
58 }
59
60 request.Header = http.Header{}
61 request.Header.Set("Accept", "application/json")
62 request.Header.Set("User-Agent", client.userAgent)
63
64 if passedRequest.Body != nil {
65 request.Header.Set("Content-Type", "application/json")
66 }
67
68 // Make sure the body is the same as the one in the request
69 return cfnetworking.NewRequest(request, passedRequest.Body), nil
70}

Callers 3

CreatePoliciesMethod · 0.95
ListPoliciesMethod · 0.95
RemovePoliciesMethod · 0.95

Calls 4

NewRequestFunction · 0.92
NewRequestMethod · 0.80
SetMethod · 0.65
CreateRequestMethod · 0.45

Tested by

no test coverage detected