in fc/runtime_api_client.go [137:167]
func (c *runtimeAPIClient) post(url string, payload []byte, contentType, httpParams string) error {
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payload))
if err != nil {
return fmt.Errorf("failed to construct POST request to %s: %v", url, err)
}
req.Header.Set("User-Agent", c.userAgent)
req.Header.Set("Content-Type", contentType)
if strings.TrimSpace(httpParams) != "" {
req.Header.Set(headerHttpParams, httpParams)
}
resp, err := c.httpClient.Do(req)
if err != nil {
return fmt.Errorf("failed to POST to %s: %v", url, err)
}
defer func() {
if err := resp.Body.Close(); err != nil {
log.Printf("runtime API client failed to close %s response body: %v", url, err)
}
}()
if resp.StatusCode != 200 {
return fmt.Errorf("failed to POST to %s: got unexpected status code: %d", url, resp.StatusCode)
}
_, err = io.Copy(ioutil.Discard, resp.Body)
if err != nil {
return fmt.Errorf("something went wrong reading the POST response from %s: %v", url, err)
}
return nil
}