chore(aws): upgrade aws dependencies

This commit is contained in:
2021-11-24 19:10:52 +01:00
parent 165108d1c3
commit b13ff06b36
229 changed files with 13263 additions and 1613 deletions

View File

@ -2,9 +2,10 @@ package http
import (
"context"
"fmt"
"github.com/aws/smithy-go/logging"
"github.com/aws/smithy-go/middleware"
"io"
"io/ioutil"
)
// AddErrorCloseResponseBodyMiddleware adds the middleware to automatically
@ -28,6 +29,8 @@ func (m *errorCloseResponseBodyMiddleware) HandleDeserialize(
out, metadata, err := next.HandleDeserialize(ctx, input)
if err != nil {
if resp, ok := out.RawResponse.(*Response); ok && resp != nil && resp.Body != nil {
// Consume the full body to prevent TCP connection resets on some platforms
_, _ = io.Copy(ioutil.Discard, resp.Body)
// Do not validate that the response closes successfully.
resp.Body.Close()
}
@ -60,8 +63,15 @@ func (m *closeResponseBody) HandleDeserialize(
}
if resp, ok := out.RawResponse.(*Response); ok {
if err = resp.Body.Close(); err != nil {
return out, metadata, fmt.Errorf("close response body failed, %w", err)
// Consume the full body to prevent TCP connection resets on some platforms
_, copyErr := io.Copy(ioutil.Discard, resp.Body)
if copyErr != nil {
middleware.GetLogger(ctx).Logf(logging.Warn, "failed to discard remaining HTTP response body, this may affect connection reuse")
}
closeErr := resp.Body.Close()
if closeErr != nil {
middleware.GetLogger(ctx).Logf(logging.Warn, "failed to close HTTP response body, this may affect connection reuse")
}
}

View File

@ -46,11 +46,13 @@ func (r *RequestResponseLogger) HandleDeserialize(
logger.Logf(logging.Debug, "Request\n%v", string(reqBytes))
smithyRequest, err = smithyRequest.SetStream(rc.Body)
if err != nil {
return out, metadata, err
if r.LogRequestWithBody {
smithyRequest, err = smithyRequest.SetStream(rc.Body)
if err != nil {
return out, metadata, err
}
in.Request = smithyRequest
}
in.Request = smithyRequest
}
out, metadata, err = next.HandleDeserialize(ctx, in)

View File

@ -0,0 +1,79 @@
package http
import (
"context"
"fmt"
"github.com/aws/smithy-go/middleware"
"strings"
)
// MinimumProtocolError is an error type indicating that the established connection did not meet the expected minimum
// HTTP protocol version.
type MinimumProtocolError struct {
proto string
expectedProtoMajor int
expectedProtoMinor int
}
// Error returns the error message.
func (m *MinimumProtocolError) Error() string {
return fmt.Sprintf("operation requires minimum HTTP protocol of HTTP/%d.%d, but was %s",
m.expectedProtoMajor, m.expectedProtoMinor, m.proto)
}
// RequireMinimumProtocol is a deserialization middleware that asserts that the established HTTP connection
// meets the minimum major ad minor version.
type RequireMinimumProtocol struct {
ProtoMajor int
ProtoMinor int
}
// AddRequireMinimumProtocol adds the RequireMinimumProtocol middleware to the stack using the provided minimum
// protocol major and minor version.
func AddRequireMinimumProtocol(stack *middleware.Stack, major, minor int) error {
return stack.Deserialize.Insert(&RequireMinimumProtocol{
ProtoMajor: major,
ProtoMinor: minor,
}, "OperationDeserializer", middleware.Before)
}
// ID returns the middleware identifier string.
func (r *RequireMinimumProtocol) ID() string {
return "RequireMinimumProtocol"
}
// HandleDeserialize asserts that the established connection is a HTTP connection with the minimum major and minor
// protocol version.
func (r *RequireMinimumProtocol) HandleDeserialize(
ctx context.Context, in middleware.DeserializeInput, next middleware.DeserializeHandler,
) (
out middleware.DeserializeOutput, metadata middleware.Metadata, err error,
) {
out, metadata, err = next.HandleDeserialize(ctx, in)
if err != nil {
return out, metadata, err
}
response, ok := out.RawResponse.(*Response)
if !ok {
return out, metadata, fmt.Errorf("unknown transport type: %T", out.RawResponse)
}
if !strings.HasPrefix(response.Proto, "HTTP") {
return out, metadata, &MinimumProtocolError{
proto: response.Proto,
expectedProtoMajor: r.ProtoMajor,
expectedProtoMinor: r.ProtoMinor,
}
}
if response.ProtoMajor < r.ProtoMajor || response.ProtoMinor < r.ProtoMinor {
return out, metadata, &MinimumProtocolError{
proto: response.Proto,
expectedProtoMajor: r.ProtoMajor,
expectedProtoMinor: r.ProtoMinor,
}
}
return out, metadata, err
}

View File

@ -130,14 +130,20 @@ func (r *Request) SetStream(reader io.Reader) (rc *Request, err error) {
func (r *Request) Build(ctx context.Context) *http.Request {
req := r.Request.Clone(ctx)
if r.stream != nil {
req.Body = iointernal.NewSafeReadCloser(ioutil.NopCloser(r.stream))
} else {
// we update the content-length to 0,
// if request stream was not set.
if r.stream == nil && req.ContentLength == -1 {
req.ContentLength = 0
}
switch stream := r.stream.(type) {
case *io.PipeReader:
req.Body = ioutil.NopCloser(stream)
req.ContentLength = -1
default:
if r.stream != nil {
req.Body = iointernal.NewSafeReadCloser(ioutil.NopCloser(stream))
}
}
return req
}