package httpimport (smithy)// ClientDo provides the interface for custom HTTP client implementations.typeClientDointerface {Do(*http.Request) (*http.Response, error)}// ClientDoFunc provides a helper to wrap a function as an HTTP client for// round tripping requests.typeClientDoFuncfunc(*http.Request) (*http.Response, error)// Do will invoke the underlying func, returning the result.func ( ClientDoFunc) ( *http.Request) (*http.Response, error) {return ()}// ClientHandler wraps a client that implements the HTTP Do method. Standard// implementation is http.Client.typeClientHandlerstruct {clientClientDo}// NewClientHandler returns an initialized middleware handler for the client.func ( ClientDo) ClientHandler {returnClientHandler{client: , }}// Handle implements the middleware Handler interface, that will invoke the// underlying HTTP client. Requires the input to be a Smithy *Request. Returns// a smithy *Response, or error if the request failed.func ( ClientHandler) ( context.Context, interface{}) (interface{}, middleware.Metadata, error,) { , := .(*Request)if ! {returnnil, , fmt.Errorf("expect Smithy http.Request value as input, got unsupported type %T", ) } := .Build()if := ValidateEndpointHost(.Host); != nil {returnnil, , } , := .client.Do()if == nil {// Ensure a http response value is always present to prevent unexpected // panics. = &http.Response{Header: http.Header{},Body: http.NoBody, } }if != nil { = &RequestSendError{Err: }// Override the error with a context canceled error, if that was canceled.select {case<-.Done(): = &smithy.CanceledError{Err: .Err()}default: } }// HTTP RoundTripper *should* close the request body. But this may not happen in a timely manner. // So instead Smithy *Request Build wraps the body to be sent in a safe closer that will clear the // stream reference so that it can be safely reused.if .Body != nil { _ = .Body.Close() }return &Response{Response: }, , }// RequestSendError provides a generic request transport error. This error// should wrap errors making HTTP client requests.//// The ClientHandler will wrap the HTTP client's error if the client request// fails, and did not fail because of context canceled.typeRequestSendErrorstruct {Errerror}// ConnectionError returns that the error is related to not being able to send// the request, or receive a response from the service.func ( *RequestSendError) () bool {returntrue}// Unwrap returns the underlying error, if there was one.func ( *RequestSendError) () error {return .Err}func ( *RequestSendError) () string {returnfmt.Sprintf("request send failed, %v", .Err)}// NopClient provides a client that ignores the request, and returns an empty// successful HTTP response value.typeNopClientstruct{}// Do ignores the request and returns a 200 status empty response.func (NopClient) ( *http.Request) (*http.Response, error) {return &http.Response{StatusCode: 200,Header: http.Header{},Body: http.NoBody, }, nil}
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)