MCPcopy Create free account
hub / github.com/goadesign/goa / RequestEncoder

Function RequestEncoder

http/encoding.go:174–186  ·  view source on GitHub ↗

RequestEncoder returns a HTTP request encoder. The encoder uses package encoding/json.

(r *http.Request)

Source from the content-addressed store, hash-verified

172// RequestEncoder returns a HTTP request encoder.
173// The encoder uses package encoding/json.
174func RequestEncoder(r *http.Request) Encoder {
175 const k = "Content-Type"
176 if h := r.Header.Get(k); h == "" {
177 r.Header.Set(k, "application/json")
178 }
179 enc := new(jsonEncoder)
180 r.Body = enc
181 // GetBody enables request retry on HTTP/2 connections when the server
182 // sends GOAWAY during graceful shutdown. Without GetBody, the HTTP transport
183 // cannot retry because the request body has already been consumed.
184 r.GetBody = enc.GetBody
185 return enc
186}
187
188// jsonEncoder implements io.ReadCloser and provides GetBody functionality
189// to support HTTP/2 request retries during server graceful shutdown (GOAWAY).

Callers 2

TestRequestEncoderFunction · 0.70

Calls 2

SetMethod · 0.80
GetMethod · 0.45

Tested by 2

TestRequestEncoderFunction · 0.56