kinesis-consumer/vendor/github.com/aws/smithy-go/transport/http/client.go
dependabot[bot] cfcdb90769
Bump the aws-sdk-go-v2 group across 1 directory with 16 updates
Bumps the aws-sdk-go-v2 group with 3 updates in the / directory: [github.com/aws/aws-sdk-go-v2/config](https://github.com/aws/aws-sdk-go-v2), [github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue](https://github.com/aws/aws-sdk-go-v2) and [github.com/aws/aws-sdk-go-v2/service/kinesis](https://github.com/aws/aws-sdk-go-v2).


Updates `github.com/aws/aws-sdk-go-v2/config` from 1.27.39 to 1.27.43
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.27.39...config/v1.27.43)

Updates `github.com/aws/aws-sdk-go-v2/credentials` from 1.17.37 to 1.17.41
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/credentials/v1.17.37...credentials/v1.17.41)

Updates `github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue` from 1.15.8 to 1.15.12
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.15.8...config/v1.15.12)

Updates `github.com/aws/aws-sdk-go-v2/service/dynamodb` from 1.35.3 to 1.36.2
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/iot/v1.35.3...service/iam/v1.36.2)

Updates `github.com/aws/aws-sdk-go-v2/service/kinesis` from 1.29.8 to 1.32.2
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/sns/v1.29.8...v1.32.2)

Updates `github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream` from 1.6.5 to 1.6.6
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/credentials/v1.6.5...service/tnb/v1.6.6)

Updates `github.com/aws/aws-sdk-go-v2/feature/ec2/imds` from 1.16.14 to 1.16.17
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.16.14...service/ram/v1.16.17)

Updates `github.com/aws/aws-sdk-go-v2/internal/configsources` from 1.3.18 to 1.3.21
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/internal/ini/v1.3.18...internal/ini/v1.3.21)

Updates `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from 2.6.18 to 2.6.21
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/internal/endpoints/v2.6.18...internal/endpoints/v2.6.21)

Updates `github.com/aws/aws-sdk-go-v2/service/dynamodbstreams` from 1.23.3 to 1.24.2
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.23.3...service/pi/v1.24.2)

Updates `github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding` from 1.11.5 to 1.12.0
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/v1.12.0/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/dlm/v1.11.5...v1.12.0)

Updates `github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery` from 1.9.19 to 1.10.2
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/memorydb/v1.9.19...config/v1.10.2)

Updates `github.com/aws/aws-sdk-go-v2/service/internal/presigned-url` from 1.11.20 to 1.12.2
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/dax/v1.11.20...service/m2/v1.12.2)

Updates `github.com/aws/aws-sdk-go-v2/service/sso` from 1.23.3 to 1.24.2
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.23.3...service/pi/v1.24.2)

Updates `github.com/aws/aws-sdk-go-v2/service/ssooidc` from 1.27.3 to 1.28.2
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.27.3...service/pi/v1.28.2)

Updates `github.com/aws/aws-sdk-go-v2/service/sts` from 1.31.3 to 1.32.2
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/s3/v1.31.3...v1.32.2)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/config
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/credentials
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/dynamodb
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/kinesis
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/feature/ec2/imds
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/internal/configsources
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/internal/endpoints/v2
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/dynamodbstreams
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/internal/presigned-url
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/sso
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/ssooidc
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
- dependency-name: github.com/aws/aws-sdk-go-v2/service/sts
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: aws-sdk-go-v2
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-09 12:53:26 +00:00

161 lines
4.7 KiB
Go

package http
import (
"context"
"fmt"
"net/http"
smithy "github.com/aws/smithy-go"
"github.com/aws/smithy-go/metrics"
"github.com/aws/smithy-go/middleware"
"github.com/aws/smithy-go/tracing"
)
// ClientDo provides the interface for custom HTTP client implementations.
type ClientDo interface {
Do(*http.Request) (*http.Response, error)
}
// ClientDoFunc provides a helper to wrap a function as an HTTP client for
// round tripping requests.
type ClientDoFunc func(*http.Request) (*http.Response, error)
// Do will invoke the underlying func, returning the result.
func (fn ClientDoFunc) Do(r *http.Request) (*http.Response, error) {
return fn(r)
}
// ClientHandler wraps a client that implements the HTTP Do method. Standard
// implementation is http.Client.
type ClientHandler struct {
client ClientDo
Meter metrics.Meter // For HTTP client metrics.
}
// NewClientHandler returns an initialized middleware handler for the client.
//
// Deprecated: Use [NewClientHandlerWithOptions].
func NewClientHandler(client ClientDo) ClientHandler {
return NewClientHandlerWithOptions(client)
}
// NewClientHandlerWithOptions returns an initialized middleware handler for the client
// with applied options.
func NewClientHandlerWithOptions(client ClientDo, opts ...func(*ClientHandler)) ClientHandler {
h := ClientHandler{
client: client,
}
for _, opt := range opts {
opt(&h)
}
if h.Meter == nil {
h.Meter = metrics.NopMeterProvider{}.Meter("")
}
return h
}
// 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 (c ClientHandler) Handle(ctx context.Context, input interface{}) (
out interface{}, metadata middleware.Metadata, err error,
) {
ctx, span := tracing.StartSpan(ctx, "DoHTTPRequest")
defer span.End()
ctx, client, err := withMetrics(ctx, c.client, c.Meter)
if err != nil {
return nil, metadata, fmt.Errorf("instrument with HTTP metrics: %w", err)
}
req, ok := input.(*Request)
if !ok {
return nil, metadata, fmt.Errorf("expect Smithy http.Request value as input, got unsupported type %T", input)
}
builtRequest := req.Build(ctx)
if err := ValidateEndpointHost(builtRequest.Host); err != nil {
return nil, metadata, err
}
span.SetProperty("http.method", req.Method)
span.SetProperty("http.request_content_length", -1) // at least indicate unknown
length, ok, err := req.StreamLength()
if err != nil {
return nil, metadata, err
}
if ok {
span.SetProperty("http.request_content_length", length)
}
resp, err := client.Do(builtRequest)
if resp == nil {
// Ensure a http response value is always present to prevent unexpected
// panics.
resp = &http.Response{
Header: http.Header{},
Body: http.NoBody,
}
}
if err != nil {
err = &RequestSendError{Err: err}
// Override the error with a context canceled error, if that was canceled.
select {
case <-ctx.Done():
err = &smithy.CanceledError{Err: ctx.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 builtRequest.Body != nil {
_ = builtRequest.Body.Close()
}
span.SetProperty("net.protocol.version", fmt.Sprintf("%d.%d", resp.ProtoMajor, resp.ProtoMinor))
span.SetProperty("http.status_code", resp.StatusCode)
span.SetProperty("http.response_content_length", resp.ContentLength)
return &Response{Response: resp}, metadata, err
}
// 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.
type RequestSendError struct {
Err error
}
// ConnectionError returns that the error is related to not being able to send
// the request, or receive a response from the service.
func (e *RequestSendError) ConnectionError() bool {
return true
}
// Unwrap returns the underlying error, if there was one.
func (e *RequestSendError) Unwrap() error {
return e.Err
}
func (e *RequestSendError) Error() string {
return fmt.Sprintf("request send failed, %v", e.Err)
}
// NopClient provides a client that ignores the request, and returns an empty
// successful HTTP response value.
type NopClient struct{}
// Do ignores the request and returns a 200 status empty response.
func (NopClient) Do(r *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: 200,
Header: http.Header{},
Body: http.NoBody,
}, nil
}