MCPcopy Index your code
hub / github.com/SpectoLabs/hoverfly / doRequest

Function doRequest

hoverctl/wrapper/hoverfly.go:266–294  ·  view source on GitHub ↗
(target configuration.Target, method, url, body string, headers map[string]string)

Source from the content-addressed store, hash-verified

264}
265
266func doRequest(target configuration.Target, method, url, body string, headers map[string]string) (*http.Response, error) {
267 url = BuildURL(target, url)
268
269 request, err := http.NewRequest(method, url, strings.NewReader(body))
270 if err != nil {
271 return nil, fmt.Errorf("Could not connect to Hoverfly at %v:%v", target.Host, target.AdminPort)
272 }
273
274 if headers != nil {
275 for key, value := range headers {
276 request.Header.Add(key, value)
277 }
278 }
279
280 if target.AuthToken != "" {
281 request.Header.Add("Authorization", fmt.Sprintf("Bearer %v", target.AuthToken))
282 }
283
284 response, err := http.DefaultClient.Do(request)
285 if err != nil {
286 return nil, fmt.Errorf("Could not connect to Hoverfly at %v:%v", target.Host, target.AdminPort)
287 }
288
289 if response.StatusCode == 401 {
290 return nil, errors.New("Hoverfly requires authentication\n\nRun `hoverctl login -t " + target.Name + "`")
291 }
292
293 return response, nil
294}
295
296func checkPorts(ports ...int) error {
297 for _, port := range ports {

Callers 15

GetLogsFunction · 0.70
GetAllJournalIndexesFunction · 0.70
SetJournalIndexFunction · 0.70
DeleteJournalIndexFunction · 0.70
GetAllPostServeActionsFunction · 0.70
SetLocalPostServeActionFunction · 0.70
SetRemotePostServeActionFunction · 0.70
DeletePostServeActionFunction · 0.70
GetModeFunction · 0.70
SetModeWithArgumentsFunction · 0.70
FlushCacheFunction · 0.70
GetCurrentStateFunction · 0.70

Calls 2

BuildURLFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected