-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove content type header from streaming operations if payload is em…
…pty or nil
- Loading branch information
1 parent
810f557
commit 54732ce
Showing
4 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package middleware | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/awslabs/smithy-go/middleware" | ||
smithyhttp "github.com/awslabs/smithy-go/transport/http" | ||
) | ||
|
||
// removeContentTypeHeader is a build middleware that removes | ||
// content type header if content-length header is unset or | ||
// is set to zero, | ||
type removeContentTypeHeader struct { | ||
} | ||
|
||
// ID the name of the middleware. | ||
func (m *removeContentTypeHeader) ID() string { | ||
return "RemoveContentTypeHeader" | ||
} | ||
|
||
// HandleBuild adds or appends the constructed user agent to the request. | ||
func (m *removeContentTypeHeader) HandleBuild(ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler) ( | ||
out middleware.BuildOutput, metadata middleware.Metadata, err error, | ||
) { | ||
req, ok := in.Request.(*smithyhttp.Request) | ||
if !ok { | ||
return out, metadata, fmt.Errorf("unknown transport type %T", in) | ||
} | ||
|
||
// remove contentTypeHeader when content-length is zero | ||
if req.ContentLength == 0 { | ||
req.Header.Del("content-type") | ||
} | ||
|
||
return next.HandleBuild(ctx, in) | ||
} | ||
|
||
// RemoveContentTypeHeader removes content-type header if | ||
// content length is unset or equal to zero. | ||
func RemoveContentTypeHeader(stack *middleware.Stack) error { | ||
return stack.Build.Add(&removeContentTypeHeader{}, middleware.After) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.