Encode returns a REST protocol encoder for encoding HTTP bindings. Due net/http requiring `Content-Length` to be specified on the http.Request#ContentLength directly. Encode will look for whether the header is present, and if so will remove it and set the respective value on http.Request. Returns
(req *http.Request)
| 59 | // |
| 60 | // Returns any error occurring during encoding. |
| 61 | func (e *Encoder) Encode(req *http.Request) (*http.Request, error) { |
| 62 | req.URL.Path, req.URL.RawPath = string(e.path), string(e.rawPath) |
| 63 | req.URL.RawQuery = e.query.Encode() |
| 64 | |
| 65 | // net/http ignores Content-Length header and requires it to be set on http.Request |
| 66 | if v := e.header.Get(contentLengthHeader); len(v) > 0 { |
| 67 | iv, err := strconv.ParseInt(v, 10, 64) |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | req.ContentLength = iv |
| 72 | e.header.Del(contentLengthHeader) |
| 73 | } |
| 74 | |
| 75 | req.Header = e.header |
| 76 | |
| 77 | return req, nil |
| 78 | } |
| 79 | |
| 80 | // AddHeader returns a HeaderValue for appending to the given header name |
| 81 | func (e *Encoder) AddHeader(key string) HeaderValue { |