| 51 | } |
| 52 | |
| 53 | func (r *Response) sendWith(client httpClient) error { |
| 54 | body, err := json.Marshal(r) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | |
| 59 | req, err := http.NewRequest(http.MethodPut, r.url, bytes.NewBuffer(body)) |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | req.Header.Del("Content-Type") |
| 64 | |
| 65 | res, err := client.Do(req) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | body, err = ioutil.ReadAll(res.Body) |
| 71 | if err != nil { |
| 72 | return err |
| 73 | } |
| 74 | res.Body.Close() |
| 75 | |
| 76 | if res.StatusCode != 200 { |
| 77 | log.Printf("StatusCode: %d\nBody: %v\n", res.StatusCode, string(body)) |
| 78 | return fmt.Errorf("invalid status code. got: %d", res.StatusCode) |
| 79 | } |
| 80 | |
| 81 | return nil |
| 82 | |
| 83 | } |
| 84 | |
| 85 | // Send will send the Response to the given URL using the |
| 86 | // default HTTP client |