Documentation ¶
Overview ¶
Package defaults is a collection of helpers to retrieve the SDK's default configuration and handlers.
Generally this package shouldn't be used directly, but external.Config instead. This package is useful when you need to reset the defaults of a service client to the SDK defaults before setting additional parameters.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AddHostExecEnvUserAgentHander = aws.NamedHandler{ Name: "core.AddHostExecEnvUserAgentHander", Fn: func(r *aws.Request) { v := os.Getenv(execEnvVar) if len(v) == 0 { return } aws.AddToUserAgent(r, execEnvUAKey+"/"+v) }, }
AddHostExecEnvUserAgentHander is a request handler appending the SDK's execution environment to the user agent.
If the environment variable AWS_EXECUTION_ENV is set, its value will be appended to the user agent string.
var AttemptClockSkewHandler = aws.NamedHandler{ Name: "core.AttemptClockSkewHandler", Fn: func(r *aws.Request) { if r.ResponseAt.IsZero() || r.HTTPResponse == nil || r.HTTPResponse.StatusCode == 0 { return } respDateHeader := r.HTTPResponse.Header.Get("Date") if len(respDateHeader) == 0 { return } respDate, err := http.ParseTime(respDateHeader) if err != nil { respDate, err = protocol.ParseTime(protocol.RFC822TimeFormatName, respDateHeader) } if err != nil { if r.Config.Logger != nil { r.Config.Logger.Log(fmt.Sprintf("ERROR: unable to determine clock skew for %s/%s API response, invalid Date header value, %v", r.Metadata.ServiceName, r.Operation.Name, respDateHeader)) } return } r.AttemptClockSkews = append(r.AttemptClockSkews, respDate.Sub(r.ResponseAt), ) }, }
AttemptClockSkewHandler records the estimated clock skew between the client and service response clocks. This estimation will be no more granular than one second. It will not be populated until after at least the first attempt's response is received.
var BuildContentLengthHandler = aws.NamedHandler{Name: "core.BuildContentLengthHandler", Fn: func(r *aws.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: var err error r.BodyStart, err = body.Seek(0, io.SeekCurrent) if err != nil { r.Error = awserr.New(aws.ErrCodeSerialization, "failed to determine start of the request body", err) } end, err := body.Seek(0, io.SeekEnd) if err != nil { r.Error = awserr.New(aws.ErrCodeSerialization, "failed to determine end of the request body", err) } _, err = body.Seek(r.BodyStart, io.SeekStart) if err != nil { r.Error = awserr.New(aws.ErrCodeSerialization, "failed to seek back to the original location", err) } 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 added 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 RequestInvocationIDHeaderHandler = aws.NamedHandler{ Name: "core.RequestInvocationIDHeaderHandler", Fn: func(r *aws.Request) { if r.ExpireTime != 0 { return } const invocationIDHeader = "amz-sdk-invocation-id" r.HTTPRequest.Header.Set(invocationIDHeader, r.InvocationID) }}
RequestInvocationIDHeaderHandler sets the invocation id header for request tracking across attempts.
var RetryMetricHeaderHandler = aws.NamedHandler{ Name: "core.RetryMetricHeaderHandler", Fn: func(r *aws.Request) { if r.ExpireTime != 0 { return } const retryMetricHeader = "amz-sdk-request" var parts []string parts = append(parts, fmt.Sprintf("attempt=%d", r.AttemptNum)) if max := r.Retryer.MaxAttempts(); max != 0 { parts = append(parts, fmt.Sprintf("max=%d", max)) } type timeoutGetter interface { GetTimeout() time.Duration } var ttl time.Time if v, ok := r.Config.HTTPClient.(timeoutGetter); ok { if t := v.GetTimeout(); t > 0 { ttl = sdk.NowTime().Add(t) } } if ttl.IsZero() { if deadline, ok := r.Context().Deadline(); ok { ttl = deadline } } if !ttl.IsZero() && len(r.AttemptClockSkews) > 0 { const unixTimeFormat = "20060102T150405Z" ttl = ttl.Add(r.AttemptClockSkews[len(r.AttemptClockSkews)-1]) parts = append(parts, fmt.Sprintf("ttl=%s", ttl.Format(unixTimeFormat))) } r.HTTPRequest.Header.Set(retryMetricHeader, strings.Join(parts, "; ")) }}
RetryMetricHeaderHandler sets an additional header to the API request that includes retry details for the service to consider.
var RetryableCheckHandler = aws.NamedHandler{ Name: "core.RetryableCheckHandler", Fn: func(r *aws.Request) { r.ShouldRetry = false retryable := r.Retryer.IsErrorRetryable(r.Error) if !retryable { return } if max := r.Retryer.MaxAttempts(); max > 0 && r.AttemptNum >= max { r.Error = &aws.MaxAttemptsError{ Attempt: r.AttemptNum, Err: r.Error, } return } var err error r.RetryDelay, err = r.Retryer.RetryDelay(r.AttemptNum, r.Error) if err != nil { r.Error = err return } r.ShouldRetry = true }}
RetryableCheckHandler performs final checks to determine if the request should be retried and how long to delay.
var SDKVersionUserAgentHandler = aws.NamedHandler{ Name: "core.SDKVersionUserAgentHandler", Fn: aws.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 = aws.NamedHandler{ Name: "core.SendHandler", Fn: func(r *aws.Request) { if http.NoBody == r.HTTPRequest.Body { reqOrig, reqCopy := r.HTTPRequest, *r.HTTPRequest reqCopy.Body = nil r.HTTPRequest = &reqCopy defer func() { r.HTTPRequest = reqOrig }() } var err error r.HTTPResponse, err = r.Config.HTTPClient.Do(r.HTTPRequest) r.ResponseAt = sdk.NowTime() if err != nil { handleSendError(r, err) } }, }
SendHandler is a request handler to send service request using HTTP client.
var ValidateEndpointHandler = aws.NamedHandler{Name: "core.ValidateEndpointHandler", Fn: func(r *aws.Request) { if r.Endpoint.SigningRegion == "" && r.Config.Region == "" { r.Error = &aws.MissingRegionError{} } else if len(r.Endpoint.URL) == 0 { r.Error = &aws.MissingEndpointError{} } }}
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 = aws.NamedHandler{Name: "core.ValidateParametersHandler", Fn: func(r *aws.Request) { if !r.ParamsFilled() { return } if v, ok := r.Params.(aws.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 ValidateReqSigHandler = aws.NamedHandler{ Name: "core.ValidateReqSigHandler", Fn: func(r *aws.Request) { if r.Config.Credentials == aws.AnonymousCredentials { return } signedTime := r.Time if !r.LastSignedAt.IsZero() { signedTime = r.LastSignedAt } if signedTime.Add(10 * time.Minute).After(time.Now()) { return } r.Sign() }, }
ValidateReqSigHandler is a request handler to ensure that the request's signature doesn't expire before it is sent. This can happen when a request is built and signed significantly before it is sent. Or significant delays occur when retrying requests that would cause the signature to expire.
var ValidateResponseHandler = aws.NamedHandler{ Name: "core.ValidateResponseHandler", Fn: func(r *aws.Request) { if r.HTTPResponse.StatusCode >= 300 { r.Error = &aws.HTTPResponseError{Response: r.HTTPResponse} } }}
ValidateResponseHandler is a request handler to validate service response.
Functions ¶
func Config ¶
Config returns the default configuration without credentials. To retrieve a config with credentials also included use `defaults.Get().Config` instead.
Generally you shouldn't need to use this method directly, but is available if you need to reset the configuration of an existing service client.
func HTTPClient ¶
func HTTPClient() aws.HTTPClient
HTTPClient will return a new HTTP Client configured for the SDK.
Does not use http.DefaultClient nor http.DefaultTransport.
Types ¶
This section is empty.