File: protocol.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.49.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312,636 kB
  • sloc: makefile: 120
file content (49 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package protocol

import (
	"fmt"
	"strings"

	"github.com/aws/aws-sdk-go/aws/awserr"
	"github.com/aws/aws-sdk-go/aws/request"
)

// RequireHTTPMinProtocol request handler is used to enforce that
// the target endpoint supports the given major and minor HTTP protocol version.
type RequireHTTPMinProtocol struct {
	Major, Minor int
}

// Handler will mark the request.Request with an error if the
// target endpoint did not connect with the required HTTP protocol
// major and minor version.
func (p RequireHTTPMinProtocol) Handler(r *request.Request) {
	if r.Error != nil || r.HTTPResponse == nil {
		return
	}

	if !strings.HasPrefix(r.HTTPResponse.Proto, "HTTP") {
		r.Error = newMinHTTPProtoError(p.Major, p.Minor, r)
	}

	if r.HTTPResponse.ProtoMajor < p.Major || r.HTTPResponse.ProtoMinor < p.Minor {
		r.Error = newMinHTTPProtoError(p.Major, p.Minor, r)
	}
}

// ErrCodeMinimumHTTPProtocolError error code is returned when the target endpoint
// did not match the required HTTP major and minor protocol version.
const ErrCodeMinimumHTTPProtocolError = "MinimumHTTPProtocolError"

func newMinHTTPProtoError(major, minor int, r *request.Request) error {
	return awserr.NewRequestFailure(
		awserr.New("MinimumHTTPProtocolError",
			fmt.Sprintf(
				"operation requires minimum HTTP protocol of HTTP/%d.%d, but was %s",
				major, minor, r.HTTPResponse.Proto,
			),
			nil,
		),
		r.HTTPResponse.StatusCode, r.RequestID,
	)
}