corehandlers

package
v0.9.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2015 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AfterRetryHandler = request.NamedHandler{"core.AfterRetryHandler", func(r *request.Request) {

	if r.Retryable == nil {
		r.Retryable = aws.Bool(r.ShouldRetry(r))
	}

	if r.WillRetry() {
		r.RetryDelay = r.RetryRules(r)
		r.Service.Config.SleepDelay(r.RetryDelay)

		if r.IsErrorExpired() {
			r.Service.Config.Credentials.Expire()
		}

		r.RetryCount++
		r.Error = nil
	}
}}

AfterRetryHandler performs final checks to determine if the request should be retried and how long to delay.

View Source
var BuildContentLengthHandler = request.NamedHandler{"core.BuildContentLengthHandler", func(r *request.Request) {
	if slength := r.HTTPRequest.Header.Get("Content-Length"); slength != "" {
		length, _ := strconv.ParseInt(slength, 10, 64)
		r.HTTPRequest.ContentLength = length
		return
	}

	var length int64
	switch body := r.Body.(type) {
	case nil:
		length = 0
	case lener:
		length = int64(body.Len())
	case io.Seeker:
		r.BodyStart, _ = body.Seek(0, 1)
		end, _ := body.Seek(0, 2)
		body.Seek(r.BodyStart, 0)
		length = end - r.BodyStart
	default:
		panic("Cannot get length of body, must provide `ContentLength`")
	}

	r.HTTPRequest.ContentLength = length
	r.HTTPRequest.Header.Set("Content-Length", fmt.Sprintf("%d", length))
}}

BuildContentLength builds the content length of a request based on the body, or will use the HTTPRequest.Header's "Content-Length" if defined. If unable to determine request body length and no "Content-Length" was specified it will panic.

View Source
var SendHandler = request.NamedHandler{"core.SendHandler", func(r *request.Request) {
	var err error
	r.HTTPResponse, err = r.Service.Config.HTTPClient.Do(r.HTTPRequest)
	if err != nil {

		if e, ok := err.(*url.Error); ok && e.Err != nil {
			if s := reStatusCode.FindStringSubmatch(e.Err.Error()); s != nil {
				code, _ := strconv.ParseInt(s[1], 10, 64)
				r.HTTPResponse = &http.Response{
					StatusCode: int(code),
					Status:     http.StatusText(int(code)),
					Body:       ioutil.NopCloser(bytes.NewReader([]byte{})),
				}
				return
			}
		}
		if r.HTTPResponse == nil {

			r.HTTPResponse = &http.Response{
				StatusCode: int(0),
				Status:     http.StatusText(int(0)),
				Body:       ioutil.NopCloser(bytes.NewReader([]byte{})),
			}
		}

		r.Error = awserr.New("RequestError", "send request failed", err)
		r.Retryable = aws.Bool(true)
	}
}}

SendHandler is a request handler to send service request using HTTP client.

View Source
var UserAgentHandler = request.NamedHandler{"core.UserAgentHandler", func(r *request.Request) {
	r.HTTPRequest.Header.Set("User-Agent", aws.SDKName+"/"+aws.SDKVersion)
}}

UserAgentHandler is a request handler for injecting User agent into requests.

View Source
var ValidateEndpointHandler = request.NamedHandler{"core.ValidateEndpointHandler", func(r *request.Request) {
	if r.Service.SigningRegion == "" && aws.StringValue(r.Service.Config.Region) == "" {
		r.Error = aws.ErrMissingRegion
	} else if r.Service.Endpoint == "" {
		r.Error = aws.ErrMissingEndpoint
	}
}}

ValidateEndpointHandler is a request handler to validate a request had the appropriate Region and Endpoint set. Will set r.Error if the endpoint or region is not valid.

View Source
var ValidateParametersHandler = request.NamedHandler{"core.ValidateParametersHandler", func(r *request.Request) {
	if r.ParamsFilled() {
		v := validator{errors: []string{}}
		v.validateAny(reflect.ValueOf(r.Params), "")

		if count := len(v.errors); count > 0 {
			format := "%d validation errors:\n- %s"
			msg := fmt.Sprintf(format, count, strings.Join(v.errors, "\n- "))
			r.Error = awserr.New("InvalidParameter", msg, nil)
		}
	}
}}

ValidateParameters is a request handler to validate the input parameters. Validating parameters only has meaning if done prior to the request being sent.

View Source
var ValidateResponseHandler = request.NamedHandler{"core.ValidateResponseHandler", func(r *request.Request) {
	if r.HTTPResponse.StatusCode == 0 || r.HTTPResponse.StatusCode >= 300 {

		r.Error = awserr.New("UnknownError", "unknown error", nil)
	}
}}

ValidateResponseHandler is a request handler to validate service response.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL