RequestEncoder returns a HTTP request encoder. The encoder uses package encoding/json.
(r *http.Request)
| 172 | // RequestEncoder returns a HTTP request encoder. |
| 173 | // The encoder uses package encoding/json. |
| 174 | func 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). |