MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / post

Method post

lambda/runtime_api_client.go:129–162  ·  view source on GitHub ↗
(url string, body io.Reader, contentType string, xrayErrorCause []byte)

Source from the content-addressed store, hash-verified

127}
128
129func (c *runtimeAPIClient) post(url string, body io.Reader, contentType string, xrayErrorCause []byte) error {
130 b := newErrorCapturingReader(body)
131 req, err := http.NewRequest(http.MethodPost, url, b)
132 if err != nil {
133 return fmt.Errorf("failed to construct POST request to %s: %v", url, err)
134 }
135 req.Trailer = b.Trailer
136 req.Header.Set("User-Agent", c.userAgent)
137 req.Header.Set("Content-Type", contentType)
138
139 if xrayErrorCause != nil && len(xrayErrorCause) < xrayErrorCauseMaxSize {
140 req.Header.Set(headerXRayErrorCause, string(xrayErrorCause))
141 }
142
143 resp, err := c.httpClient.Do(req)
144 if err != nil {
145 return fmt.Errorf("failed to POST to %s: %v", url, err)
146 }
147 defer func() {
148 if err := resp.Body.Close(); err != nil {
149 log.Printf("runtime API client failed to close %s response body: %v", url, err)
150 }
151 }()
152 if resp.StatusCode != http.StatusAccepted {
153 return fmt.Errorf("failed to POST to %s: got unexpected status code: %d", url, resp.StatusCode)
154 }
155
156 _, err = io.Copy(ioutil.Discard, resp.Body)
157 if err != nil {
158 return fmt.Errorf("something went wrong reading the POST response from %s: %v", url, err)
159 }
160
161 return nil
162}
163
164func newErrorCapturingReader(r io.Reader) *errorCapturingReader {
165 trailer := http.Header{

Callers 2

successMethod · 0.80
failureMethod · 0.80

Calls 3

newErrorCapturingReaderFunction · 0.85
DoMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected