aws-sdk-go: github.com/GregorioDiStefano/aws-sdk-go/aws/corehandlers Index | Files

package corehandlers

import "github.com/GregorioDiStefano/aws-sdk-go/aws/corehandlers"

Index

Package Files

handlers.go param_validator.go

Variables

var AfterRetryHandler = request.NamedHandler{Name: "core.AfterRetryHandler", Fn: func(r *request.Request) {

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

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

        if r.IsErrorExpired() {
            r.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.

var BuildContentLengthHandler = request.NamedHandler{Name: "core.BuildContentLengthHandler", Fn: func(r *request.Request) {
    var length int64

    if slength := r.HTTPRequest.Header.Get("Content-Length"); slength != "" {
        length, _ = strconv.ParseInt(slength, 10, 64)
    } else {
        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`")
        }
    }

    if length > 0 {
        r.HTTPRequest.ContentLength = length
        r.HTTPRequest.Header.Set("Content-Length", fmt.Sprintf("%d", length))
    } else {
        r.HTTPRequest.ContentLength = 0
        r.HTTPRequest.Header.Del("Content-Length")
    }
}}

BuildContentLengthHandler 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.

The Content-Length will only be aded to the request if the length of the body is greater than 0. If the body is empty or the current `Content-Length` header is <= 0, the header will also be stripped.

var SDKVersionUserAgentHandler = request.NamedHandler{
    Name: "core.SDKVersionUserAgentHandler",
    Fn: request.MakeAddToUserAgentHandler(aws.SDKName, aws.SDKVersion,
        runtime.Version(), runtime.GOOS, runtime.GOARCH),
}

SDKVersionUserAgentHandler is a request handler for adding the SDK Version to the user agent.

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

        if r.HTTPResponse != nil {
            r.HTTPResponse.Body.Close()
        }

        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.

var ValidateEndpointHandler = request.NamedHandler{Name: "core.ValidateEndpointHandler", Fn: func(r *request.Request) {
    if r.ClientInfo.SigningRegion == "" && aws.StringValue(r.Config.Region) == "" {
        r.Error = aws.ErrMissingRegion
    } else if r.ClientInfo.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.

var ValidateParametersHandler = request.NamedHandler{Name: "core.ValidateParametersHandler", Fn: func(r *request.Request) {
    if !r.ParamsFilled() {
        return
    }

    if v, ok := r.Params.(request.Validator); ok {
        if err := v.Validate(); err != nil {
            r.Error = err
        }
    }
}}

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

var ValidateResponseHandler = request.NamedHandler{Name: "core.ValidateResponseHandler", Fn: 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.

Package corehandlers imports 12 packages (graph). Updated 2016-12-27. Refresh now. Tools for package owners. This is a quick bug-fix fork (has fewer than three commits, and only during the week it was created).