6 "github.com/aws/aws-sdk-go/aws/request"
9 // ValidateEndpointHostHandler is a request handler that will validate the
10 // request endpoint's hosts is a valid RFC 3986 host.
11 var ValidateEndpointHostHandler = request.NamedHandler{
12 Name: "awssdk.protocol.ValidateEndpointHostHandler",
13 Fn: func(r *request.Request) {
14 err := ValidateEndpointHost(r.Operation.Name, r.HTTPRequest.URL.Host)
21 // ValidateEndpointHost validates that the host string passed in is a valid RFC
22 // 3986 host. Returns error if the host is not valid.
23 func ValidateEndpointHost(opName, host string) error {
24 paramErrs := request.ErrInvalidParams{Context: opName}
25 labels := strings.Split(host, ".")
27 for i, label := range labels {
28 if i == len(labels)-1 && len(label) == 0 {
29 // Allow trailing dot for FQDN hosts.
33 if !ValidHostLabel(label) {
34 paramErrs.Add(request.NewErrParamFormat(
35 "endpoint host label", "[a-zA-Z0-9-]{1,63}", label))
40 paramErrs.Add(request.NewErrParamMaxLen(
41 "endpoint host", 255, host,
45 if paramErrs.Len() > 0 {
51 // ValidHostLabel returns if the label is a valid RFC 3986 host label.
52 func ValidHostLabel(label string) bool {
53 if l := len(label); l == 0 || l > 63 {
56 for _, r := range label {
58 case r >= '0' && r <= '9':
59 case r >= 'A' && r <= 'Z':
60 case r >= 'a' && r <= 'z':