github.com/aavshr/aws-sdk-go@v1.41.3/private/protocol/protocol.go (about) 1 package protocol 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/aavshr/aws-sdk-go/aws/awserr" 8 "github.com/aavshr/aws-sdk-go/aws/request" 9 ) 10 11 // RequireHTTPMinProtocol request handler is used to enforce that 12 // the target endpoint supports the given major and minor HTTP protocol version. 13 type RequireHTTPMinProtocol struct { 14 Major, Minor int 15 } 16 17 // Handler will mark the request.Request with an error if the 18 // target endpoint did not connect with the required HTTP protocol 19 // major and minor version. 20 func (p RequireHTTPMinProtocol) Handler(r *request.Request) { 21 if r.Error != nil || r.HTTPResponse == nil { 22 return 23 } 24 25 if !strings.HasPrefix(r.HTTPResponse.Proto, "HTTP") { 26 r.Error = newMinHTTPProtoError(p.Major, p.Minor, r) 27 } 28 29 if r.HTTPResponse.ProtoMajor < p.Major || r.HTTPResponse.ProtoMinor < p.Minor { 30 r.Error = newMinHTTPProtoError(p.Major, p.Minor, r) 31 } 32 } 33 34 // ErrCodeMinimumHTTPProtocolError error code is returned when the target endpoint 35 // did not match the required HTTP major and minor protocol version. 36 const ErrCodeMinimumHTTPProtocolError = "MinimumHTTPProtocolError" 37 38 func newMinHTTPProtoError(major, minor int, r *request.Request) error { 39 return awserr.NewRequestFailure( 40 awserr.New("MinimumHTTPProtocolError", 41 fmt.Sprintf( 42 "operation requires minimum HTTP protocol of HTTP/%d.%d, but was %s", 43 major, minor, r.HTTPResponse.Proto, 44 ), 45 nil, 46 ), 47 r.HTTPResponse.StatusCode, r.RequestID, 48 ) 49 }