Package: request

import "../ibm-cos-sdk-go/aws/request"

Constants

const WaiterResourceNotReadyErrorCode = readonly

WaiterResourceNotReadyErrorCode is the error code returned by a waiter when the waiter's max attempts have been exhausted.

Value:

"ResourceNotReady"
const SuccessWaiterState WaiterState = readonly

Value:

iota // waiter successful
const PathAllWaiterMatch WaiterMatchMode = readonly

Value:

iota // match on all paths
const ErrCodeSerialization = readonly

ErrCodeSerialization is the serialization error code that is received during protocol unmarshaling.

Value:

"SerializationError"
const ErrCodeRead = readonly

ErrCodeRead is an error that is returned during HTTP reads.

Value:

"ReadError"
const ErrCodeResponseTimeout = readonly

ErrCodeResponseTimeout is the connection timeout error that is received during body reads.

Value:

"ResponseTimeout"
const ErrCodeInvalidPresignExpire = readonly

ErrCodeInvalidPresignExpire is returned when the expire time provided to presign is invalid

Value:

"InvalidPresignExpireError"
const CanceledErrorCode = readonly

CanceledErrorCode is the error code that will be returned by an API request that was canceled. Requests given a aws.Context may return this error when canceled.

Value:

"RequestCanceled"
const ErrCodeRequestError = readonly

ErrCodeRequestError is an error preventing the SDK from continuing to process the request.

Value:

"RequestError"
const InvalidParameterErrCode = readonly

InvalidParameterErrCode is the error code for invalid parameters errors

Value:

"InvalidParameter"
const ParamRequiredErrCode = readonly

ParamRequiredErrCode is the error code for required parameter errors

Value:

"ParamRequiredError"
const ParamMinValueErrCode = readonly

ParamMinValueErrCode is the error code for fields with too low of a number value.

Value:

"ParamMinValueError"
const ParamMinLenErrCode = readonly

ParamMinLenErrCode is the error code for fields without enough elements.

Value:

"ParamMinLenError"
const ParamMaxLenErrCode = readonly

ParamMaxLenErrCode is the error code for value being too long.

Value:

"ParamMaxLenError"
const ParamFormatErrCode = readonly

ParamFormatErrCode is the error code for a field with invalid format or characters.

Value:

"ParamFormatInvalidError"
const HandlerResponseTimeout = readonly

HandlerResponseTimeout is what we use to signify the name of the response timeout handler.

Value:

"ResponseTimeoutHandler"

Variables

var NoBody = writable

NoBody is a http.NoBody reader instructing Go HTTP client to not include and body in the HTTP request.

Value:

http.NoBody

Type Summary collapse

Interface Summary collapse

Function Summary collapse

Type Details

HandlerListRunItem struct

A HandlerListRunItem represents an entry in the HandlerList which is being run.

Structure Fields:

Index int
Handler NamedHandler
Request *Request

NamedHandler struct

A NamedHandler is a struct that contains a name and function callback.

Structure Fields:

Name string
Fn func(*Request)

Operation struct

An Operation is the service API operation to be made.

Structure Fields:

Name string
HTTPMethod string
HTTPPath string

Paginator struct

A Paginator is the configuration data that defines how an API operation should be paginated. This type is used by the API service models to define the generated pagination config for service APIs.

The Pagination type is what provides iterating between pages of an API. It is only used to store the token metadata the SDK should use for performing pagination.

Structure Fields:

InputTokens []string
OutputTokens []string
LimitToken string
TruncationToken string

WaiterMatchMode struct

String returns the string representation of the waiter match mode.

Structure Fields:

(empty struct)

WaiterState struct

String returns the string representation of the waiter state.

Structure Fields:

(empty struct)

Function Details

func AddToUserAgent(r *Request, s string)

AddToUserAgent adds the string to the end of the request's current user agent.



642
643
644
645
646
647
648
// File 'aws/request/request.go', line 642

func AddToUserAgent(r *Request, s string) { curUA := r.HTTPRequest.Header.Get("User-Agent") if len(curUA) > 0 { s = curUA + " " + s } r.HTTPRequest.Header.Set("User-Agent", s) }

func ConstantWaiterDelay(delay time.Duration) WaiterDelay

ConstantWaiterDelay returns a WaiterDelay that will always return a constant delay the waiter should use between attempts. It ignores the number of attempts made.



38
39
40
41
42
// File 'aws/request/waiter.go', line 38

func ConstantWaiterDelay(delay time.Duration) WaiterDelay { return func(attempt int) time.Duration { return delay } }

func HandlerListLogItem(item HandlerListRunItem) bool

HandlerListLogItem logs the request handler and the state of the request's Error value. Always returns true to continue iterating request handlers in a HandlerList.



279
280
281
282
283
284
285
286
287
// File 'aws/request/handlers.go', line 279

func HandlerListLogItem(item HandlerListRunItem) bool { if item.Request.Config.Logger == nil { return true } item.Request.Config.Logger.Log("DEBUG: RequestHandler", item.Index, item.Handler.Name, item.Request.Error) return true }

func HandlerListStopOnError(item HandlerListRunItem) bool

HandlerListStopOnError returns false to stop the HandlerList iterating over request handlers if Request.Error is not nil. True otherwise to continue iterating.



292
293
294
// File 'aws/request/handlers.go', line 292

func HandlerListStopOnError(item HandlerListRunItem) bool { return item.Request.Error == nil }

func IsErrorExpiredCreds(err error) bool

IsErrorExpiredCreds returns whether the error code is a credential expiry error. Returns false if error is nil.



238
239
240
241
242
243
// File 'aws/request/retryer.go', line 238

func IsErrorExpiredCreds(err error) bool { if aerr, ok := err.(awserr.Error); ok && aerr != nil { return isCodeExpiredCreds(aerr.Code()) } return false }

func IsErrorRetryable(err error) bool

IsErrorRetryable returns whether the error is retryable, based on its Code. Returns false if error is nil.



156
157
158
159
160
161
// File 'aws/request/retryer.go', line 156

func IsErrorRetryable(err error) bool { if err == nil { return false } return shouldRetryError(err) }

func IsErrorThrottle(err error) bool

IsErrorThrottle returns whether the error is to be throttled based on its code. Returns false if error is nil.



229
230
231
232
233
234
// File 'aws/request/retryer.go', line 229

func IsErrorThrottle(err error) bool { if aerr, ok := err.(awserr.Error); ok && aerr != nil { return isCodeThrottle(aerr.Code()) } return false }

func MakeAddToUserAgentFreeFormHandler(s string) func(*Request)

MakeAddToUserAgentFreeFormHandler adds the input to the User-Agent request header. The input string will be concatenated with the current request's user agent string.



323
324
325
326
327
// File 'aws/request/handlers.go', line 323

func MakeAddToUserAgentFreeFormHandler(s string) func(*Request) { return func(r *Request) { AddToUserAgent(r, s) } }

func MakeAddToUserAgentHandler(name, version string, extra ...string) func(*Request)

MakeAddToUserAgentHandler will add the name/version pair to the User-Agent request header. If the extra parameters are provided they will be added as metadata to the name/version pair resulting in the following format. “name/version (extra0; extra1; …)” The user agent part will be concatenated with this current request's user agent string.



311
312
313
314
315
316
317
318
319
// File 'aws/request/handlers.go', line 311

func MakeAddToUserAgentHandler(name, version string, extra ...string) func(*Request) { ua := fmt.Sprintf("%s/%s", name, version) if len(extra) > 0 { ua += fmt.Sprintf(" (%s)", strings.Join(extra, "; ")) } return func(r *Request) { AddToUserAgent(r, ua) } }

func SanitizeHostForHeader(r *http.Request)

SanitizeHostForHeader removes default port from host and updates request.Host



651
652
653
654
655
656
657
// File 'aws/request/request.go', line 651

func SanitizeHostForHeader(r *http.Request) { host := getHost(r) port := portOnly(host) if port != "" && isDefaultPort(r.URL.Scheme, port) { r.Host = stripPort(host) } }

func WithAppendUserAgent(s string) Option

WithAppendUserAgent will add a string to the user agent prefixed with a single white space.



298
299
300
301
302
303
304
// File 'aws/request/handlers.go', line 298

func WithAppendUserAgent(s string) Option { return func(r *Request) { r.Handlers.Build.PushBack(func(r2 *Request) { AddToUserAgent(r, s) }) } }

func WithGetResponseHeader(key string, val *string) Option

WithGetResponseHeader builds a request Option which will retrieve a single header value from the HTTP Response. If there are multiple values for the header key use WithGetResponseHeaders instead to access the http.Header map directly. The passed in val pointer must be non-nil.

This Option can be used multiple times with a single API operation.

var id2, versionID string svc.PutObjectWithContext(ctx, params, request.WithGetResponseHeader("x-amz-id-2", &id2), request.WithGetResponseHeader("x-amz-version-id", &versionID), )


189
190
191
192
193
194
195
// File 'aws/request/request.go', line 189

func WithGetResponseHeader(key string, val *string) Option { return func(r *Request) { r.Handlers.Complete.PushBack(func(req *Request) { *val = req.HTTPResponse.Header.Get(key) }) } }

func WithGetResponseHeaders(headers *http.Header) Option

WithGetResponseHeaders builds a request Option which will retrieve the headers from the HTTP response and assign them to the passed in headers variable. The passed in headers pointer must be non-nil.

var headers http.Header svc.PutObjectWithContext(ctx, params, request.WithGetResponseHeaders(&headers))


203
204
205
206
207
208
209
// File 'aws/request/request.go', line 203

func WithGetResponseHeaders(headers *http.Header) Option { return func(r *Request) { r.Handlers.Complete.PushBack(func(req *Request) { *headers = req.HTTPResponse.Header }) } }

func WithLogLevel(l aws.LogLevelType) Option

WithLogLevel is a request option that will set the request to use a specific log level when the request is made.

svc.PutObjectWithContext(ctx, params, request.WithLogLevel(aws.LogDebugWithHTTPBody)


215
216
217
218
219
// File 'aws/request/request.go', line 215

func WithLogLevel(l aws.LogLevelType) Option { return func(r *Request) { r.Config.LogLevel = aws.LogLevel(l) } }

func WithResponseReadTimeout(duration time.Duration) Option

WithResponseReadTimeout is a request option that will wrap the body in a timeout read closer. This will allow for per read timeouts. If a timeout occurred, we will return the ErrCodeResponseTimeout.

svc.PutObjectWithContext(ctx, params, request.WithTimeoutReadCloser(30 * time.Second)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// File 'aws/request/timeout_read_closer.go', line 74

func WithResponseReadTimeout(duration time.Duration) Option { return func(r *Request) { var timeoutHandler = NamedHandler{ HandlerResponseTimeout, func(req *Request) { req.HTTPResponse.Body = &timeoutReadCloser{ reader: req.HTTPResponse.Body, duration: duration, } }} // remove the handler so we are not stomping over any new durations. r.Handlers.Send.RemoveByName(HandlerResponseTimeout) r.Handlers.Send.PushBackNamed(timeoutHandler) r.Handlers.Unmarshal.PushBack(adaptToResponseTimeoutError) r.Handlers.UnmarshalError.PushBack(adaptToResponseTimeoutError) } }

func WithRetryer(cfg *aws.Config, retryer Retryer) *aws.Config

WithRetryer sets a Retryer value to the given Config returning the Config value for chaining. The value must not be nil.



38
39
40
41
42
43
44
45
46
47
48
// File 'aws/request/retryer.go', line 38

func WithRetryer(cfg *aws.Config, retryer Retryer) *aws.Config { if retryer == nil { if cfg.Logger != nil { cfg.Logger.Log("ERROR: Request.WithRetryer called with nil retryer. Replacing with retry disabled Retryer.") } retryer = noOpRetryer{} } cfg.Retryer = retryer return cfg }

func WithSetRequestHeaders(h map[string]string) Option

WithSetRequestHeaders updates the operation request's HTTP header to contain the header key value pairs provided. If the header key already exists in the request's HTTP header set, the existing value(s) will be replaced.

Header keys added will be added as canonical format with title casing applied via http.Header.Set method.



335
336
337
// File 'aws/request/handlers.go', line 335

func WithSetRequestHeaders(h map[string]string) Option { return withRequestHeader(h).SetRequestHeaders }

func WithWaiterDelay(delayer WaiterDelay) WaiterOption

WithWaiterDelay will set the Waiter to use the WaiterDelay passed in.



45
46
47
48
49
// File 'aws/request/waiter.go', line 45

func WithWaiterDelay(delayer WaiterDelay) WaiterOption { return func(w *Waiter) { w.Delay = delayer } }

func WithWaiterLogger(logger aws.Logger) WaiterOption

WithWaiterLogger returns a waiter option to set the logger a waiter should use to log warnings and errors to.



53
54
55
56
57
// File 'aws/request/waiter.go', line 53

func WithWaiterLogger(logger aws.Logger) WaiterOption { return func(w *Waiter) { w.Logger = logger } }

func WithWaiterMaxAttempts(max int) WaiterOption

WithWaiterMaxAttempts returns the maximum number of times the waiter should attempt to check the resource for the target state.



21
22
23
24
25
// File 'aws/request/waiter.go', line 21

func WithWaiterMaxAttempts(max int) WaiterOption { return func(w *Waiter) { w.MaxAttempts = max } }

func WithWaiterRequestOptions(opts ...Option) WaiterOption

WithWaiterRequestOptions returns a waiter option setting the request options for each request the waiter makes. Appends to waiter's request options already set.



62
63
64
65
66
// File 'aws/request/waiter.go', line 62

func WithWaiterRequestOptions(opts ...Option) WaiterOption { return func(w *Waiter) { w.RequestOptions = append(w.RequestOptions, opts...) } }