formatRequest generates ascii representation of a request
(r *http.Request, reqParams map[string]interface{})
| 348 | |
| 349 | // formatRequest generates ascii representation of a request |
| 350 | func 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 |
| 383 | func parsingResponse(resp *http.Response) (string, error) { |