Skip to content

Missing Content-Length header for zero size objects #3080

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

Open
3 tasks done
ybizeul opened this issue May 2, 2025 · 2 comments · May be fixed by #3086
Open
3 tasks done

Missing Content-Length header for zero size objects #3080

ybizeul opened this issue May 2, 2025 · 2 comments · May be fixed by #3086
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. potential-regression Marking this issue as a potential regression to be checked by team member

Comments

@ybizeul
Copy link

ybizeul commented May 2, 2025

Acknowledgements

Describe the bug

I recognize it is a tricky one because I'm not working with AWS but with MinIO S3 server.

The issue seems to be that a change occurred since 1.30.4 which was working fine.

Now when I send a zero size object to MinIO, I'm getting the following error :

api error MissingContentLength: You must provide the Content-Length HTTP header.

It seems for some reason, aws-sdk or smithy somewhere decided to skip Content-Length when it's zero

Any idea why that would be ?

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Zero file size should be sent with Content-Length: 0

Current Behavior

Content-Length is not sent as part of headers

Reproduction Steps

as this probably works fine with AWS S3, not including code sample.

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

v1.36.3

Compiler and Version used

go version go1.24.1 darwin/arm64

Operating System and version

macOS 15.4.1

@ybizeul ybizeul added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 2, 2025
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label May 2, 2025
@wty-Bryant
Copy link
Contributor

Could you provide sample code of calling s3 using aws-sdk-go-v2? MinIO is a service owned by separate entity that mimics s3 client/server which is out of our sdk scope.

@wty-Bryant wty-Bryant added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 2, 2025
@ybizeul
Copy link
Author

ybizeul commented May 2, 2025

So that's interesting. Don't ask why, but for some reason I'm currently initializing my buffer with :

b = bufio.NewReader(bytes.NewBuffer(data))

The above fails with AWS bucket the same way it fails with MinIO

I also need some time to use a io.LimitReader, which also fails.

But if I use :

b = bytes.NewReader(data)

Then everything works.

I'm wondering, does the library need a seekable reader ?

Full code :

package main

import (
	"bufio"
	"bytes"
	"context"
	"io"
	"log"
	"net/http"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/credentials"
	"github.com/aws/aws-sdk-go-v2/service/s3"
)

var AWS_KEY string = "<redacted>"
var AWS_SECRET string = "<redacted>"
var ENDPOINT string = "https://s3.eu-west-3.amazonaws.com/"
var BUCKET string = "hupload-test"

func main() {
	c, err := config.LoadDefaultConfig(
		context.Background(),
		config.WithRegion("eu-west-3"),
		config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(AWS_KEY, AWS_SECRET, "")),
		config.WithHTTPClient(&http.Client{
			Timeout: 0,
		}),
	)
	if err != nil {
		log.Fatal(err)
	}

	data := []byte{}

	var b io.Reader

	OPTION := 1

	switch OPTION {
	case 1:
		// Fails
		b = bufio.NewReader(bytes.NewBuffer(data))
	case 2:
		// Works
		b = bytes.NewReader(data)
	case 3:
		// Fails
		b = io.LimitReader(bytes.NewReader(data), 1024)
	}
	client := s3.NewFromConfig(c, func(o *s3.Options) {
		o.UsePathStyle = true
		o.BaseEndpoint = &ENDPOINT
	})
	size := int64(len(data))
	key := "sample/testFile"
	input := &s3.PutObjectInput{
		Bucket:        &BUCKET,
		Key:           &key,
		Body:          b,
		ContentLength: &size,
	}
	_, err = client.PutObject(context.Background(), input)
	if err != nil {
		log.Fatal(err)
	}
}

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. potential-regression Marking this issue as a potential regression to be checked by team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants