// Code generated by smithy-go-codegen DO NOT EDIT.

package query

import (
	"context"
	"fmt"
	smithyendpoints "github.com/aws/smithy-go/endpoints"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
	"io"
	"net/http"
	"net/url"
	"strconv"
	"strings"
)

type protocolTestHTTPClient struct{}

func (*protocolTestHTTPClient) Do(r *http.Request) (*http.Response, error) {
	return &http.Response{
		StatusCode: 200,
		Header:     r.Header,
		Body:       io.NopCloser(strings.NewReader("")),
		Request:    r,
	}, nil
}

func (*protocolTestEndpointResolver) Do(r *http.Request) (*http.Response, error) {
	return &http.Response{
		StatusCode: 200,
		Header:     r.Header,
		Body:       io.NopCloser(strings.NewReader("")),
		Request:    r,
	}, nil
}

type protocolTestEndpointResolver struct {
	URL string
}

func (r *protocolTestEndpointResolver) ResolveEndpoint(ctx context.Context, params EndpointParameters) (
	smithyendpoints.Endpoint, error,
) {
	u, err := url.Parse(r.URL)
	if err != nil {
		return smithyendpoints.Endpoint{}, err
	}

	return smithyendpoints.Endpoint{URI: *u}, nil
}

type captureRequestMiddleware struct {
	req *http.Request
}

func (*captureRequestMiddleware) ID() string {
	return "captureRequest"
}

func (m *captureRequestMiddleware) HandleFinalize(
	ctx context.Context, input middleware.FinalizeInput, next middleware.FinalizeHandler,
) (
	out middleware.FinalizeOutput, md middleware.Metadata, err error,
) {
	req, ok := input.Request.(*smithyhttp.Request)
	if !ok {
		return out, md, fmt.Errorf("unexpected transport type %T", req)
	}

	*m.req = *req.Build(ctx)

	if len(m.req.URL.RawPath) == 0 || m.req.URL.RawPath == "/" {
		m.req.URL.RawPath = m.req.URL.Path
	}
	if v := m.req.ContentLength; v != 0 {
		m.req.Header.Set("Content-Length", strconv.FormatInt(v, 10))
	}

	return next.HandleFinalize(ctx, input)
}
