File: accept_header.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (38 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package customizations

import (
	"context"
	"fmt"

	"github.com/aws/smithy-go/middleware"
	"github.com/aws/smithy-go/transport/http"
)

// AddAcceptHeader is the helper function used to add middleware to the stack
func AddAcceptHeader(stack *middleware.Stack) error {
	return stack.Build.Add(&acceptHeader{}, middleware.After)
}

type acceptHeader struct{}

// ID returns the middleware ID.
func (*acceptHeader) ID() string {
	return "APIGATEWAY:AcceptHeader"
}

// HandleBuild handles the associated build step of middleware stack
func (m *acceptHeader) HandleBuild(
	ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler) (
	out middleware.BuildOutput, metadata middleware.Metadata, err error,
) {
	req, ok := in.Request.(*http.Request)
	if !ok {
		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
	}

	// all APIGateway operations must have Accept header set to application/json
	const conHeader = "Accept"
	req.Header[conHeader] = append(req.Header[conHeader][:0], "application/json")

	return next.HandleBuild(ctx, in)
}