MCPcopy Create free account
hub / github.com/aws/smithy-go / Encode

Method Encode

encoding/httpbinding/encode.go:61–78  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

59//
60// Returns any error occurring during encoding.
61func (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
81func (e *Encoder) AddHeader(key string) HeaderValue {

Callers 5

TestEncoderFunction · 0.95
TestEncodeContentLengthFunction · 0.95
CollectUnknownFieldFunction · 0.95
encodeByteSliceFunction · 0.45
encodeByteSliceFunction · 0.45

Calls 2

DelMethod · 0.80
GetMethod · 0.65

Tested by 2

TestEncoderFunction · 0.76
TestEncodeContentLengthFunction · 0.76