MCPcopy
hub / github.com/cloudflare/cloudflared / sendRequest

Method sendRequest

cfapi/base_client.go:87–108  ·  view source on GitHub ↗
(method string, url url.URL, body interface{})

Source from the content-addressed store, hash-verified

85}
86
87func (r *RESTClient) sendRequest(method string, url url.URL, body interface{}) (*http.Response, error) {
88 var bodyReader io.Reader
89 if body != nil {
90 if bodyBytes, err := json.Marshal(body); err != nil {
91 return nil, errors.Wrap(err, "failed to serialize json body")
92 } else {
93 bodyReader = bytes.NewBuffer(bodyBytes)
94 }
95 }
96
97 req, err := http.NewRequest(method, url.String(), bodyReader)
98 if err != nil {
99 return nil, errors.Wrapf(err, "can't create %s request", method)
100 }
101 req.Header.Set("User-Agent", r.userAgent)
102 if bodyReader != nil {
103 req.Header.Set("Content-Type", jsonContentType)
104 }
105 req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", r.authToken))
106 req.Header.Add("Accept", "application/json;version=1")
107 return r.client.Do(req)
108}
109
110func parseResponseEnvelope(reader io.Reader) (*response, error) {
111 // Schema for Tunnelstore responses in the v1 API.

Callers 15

RouteTunnelMethod · 0.95
CreateVirtualNetworkMethod · 0.95
ListVirtualNetworksMethod · 0.95
DeleteVirtualNetworkMethod · 0.95
UpdateVirtualNetworkMethod · 0.95
ListRoutesMethod · 0.95
AddRouteMethod · 0.95
DeleteRouteMethod · 0.95
GetByIPMethod · 0.95
CreateTunnelMethod · 0.95
GetTunnelMethod · 0.95
GetTunnelTokenMethod · 0.95

Calls 5

StringMethod · 0.65
AddMethod · 0.65
MarshalMethod · 0.45
SetMethod · 0.45
DoMethod · 0.45

Tested by

no test coverage detected