-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Presigned links: Unable to set Content-Length in X-Amz-SignedHeaders #1418
Comments
This issue is pretty much reproducible and a breaker from the previous version. |
As a temporary work-around setting package main
import (
"bytes"
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"io"
"math/rand"
"net/http"
"net/url"
"strconv"
)
func main() {
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion("us-west-2"))
if err != nil {
panic(err)
}
client := s3.NewFromConfig(cfg)
presignClient := s3.NewPresignClient(client)
httpRequest, err := presignClient.PresignPutObject(context.Background(), &s3.PutObjectInput{
Bucket: aws.String("mcgrails-test-data"),
Key: aws.String("workarond"),
ContentLength: 100,
Body: http.NoBody,
}, func(options *s3.PresignOptions) {
options.ClientOptions = append(options.ClientOptions, func(options *s3.Options) {
options.ClientLogMode |= aws.LogSigning
})
})
if err != nil {
panic(err)
}
data := make([]byte, 100)
_, err = rand.Read(data)
if err != nil {
panic(err)
}
p, err := url.Parse(httpRequest.URL)
if err != nil {
panic(err)
}
// Go's standard HTTP Client won't honor the header unless we pull it out here and specify it on request directly
// so doing that here for POC for fix.
contentLength, err := strconv.Atoi(httpRequest.SignedHeader.Get("Content-Length"))
if err != nil {
panic(err)
}
response, err := http.DefaultClient.Do(&http.Request{
Method: httpRequest.Method,
URL: p,
ContentLength: int64(contentLength),
Header: httpRequest.SignedHeader,
Body: io.NopCloser(bytes.NewReader(data)),
})
if err != nil {
panic(err)
}
respBody, err := io.ReadAll(response.Body)
if err != nil {
panic(err)
}
fmt.Println(response.StatusCode)
fmt.Printf("%s", respBody)
} |
|
Confirm by changing [ ] to [x] below to ensure that it's a bug:
Describe the bug
Upgrading from v1 to v2, I am unable to set
X-Amz-SignedHeaders=content-length
when creating pre-signed upload links. After settingContentLength
in thes3.PutObjectInput
struct, I expected this to be included in the signed headers as it was in v1. I was expecting it to work the same as settingContentType
in thes3.PutObjectInput
struct which does addcontent-type
to the signed headers.Version of AWS SDK for Go?
Version of Go (
go version
)?go version go1.17 darwin/amd64
To Reproduce (observed behavior)
Expected behavior
Content length set in signed headers:
X-Amz-SignedHeaders=content-length&host
Additional context
The text was updated successfully, but these errors were encountered: