MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / formatRequest

Function formatRequest

cli/pkg/common/http.go:350–380  ·  view source on GitHub ↗

formatRequest generates ascii representation of a request

(r *http.Request, reqParams map[string]interface{})

Source from the content-addressed store, hash-verified

348
349// formatRequest generates ascii representation of a request
350func formatRequest(r *http.Request, reqParams map[string]interface{}) string {
351 // Create return string
352 var messages []string
353 // Add the request string
354 url := fmt.Sprintf("%v %v %v", r.Method, r.URL, r.Proto)
355 messages = append(messages, url)
356 // Add the host
357 messages = append(messages, fmt.Sprintf("Host: %v", r.Host))
358 // Loop through headers
359 for name, headers := range r.Header {
360 name = strings.ToLower(name)
361 for _, h := range headers {
362 messages = append(messages, fmt.Sprintf("%v: %v", name, h))
363 }
364 }
365
366 // If this is a POST, add post data
367 if r.Method == "POST" {
368 r.ParseForm()
369 messages = append(messages, "\n")
370 messages = append(messages, r.Form.Encode())
371 }
372
373 if reqParams != nil {
374 j, _ := json.Marshal(reqParams)
375 messages = append(messages, string(j))
376 }
377
378 // Return the request as a string
379 return "REQUEST \n\t" + strings.Join(messages, "\n\t")
380}
381
382// response format
383func parsingResponse(resp *http.Response) (string, error) {

Callers 3

getMethod · 0.85
putMethod · 0.85
postMethod · 0.85

Calls 1

JoinMethod · 0.45

Tested by

no test coverage detected