Skip to content
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

Pass contentLength to the worker #791

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,13 @@ type (
ContractSet string
MimeType string
DisablePreshardingEncryption bool
Size int64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Size int64
ContentLength int64

}

UploadMultipartUploadPartOptions struct {
DisablePreshardingEncryption bool
EncryptionOffset int
ContentLength int64
}
)

Expand Down
5 changes: 4 additions & 1 deletion s3/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ func (s *s3) DeleteObject(ctx context.Context, bucketName, objectName string) (g
// TODO: Metadata is currently ignored. The backend requires an update to
// support it.
func (s *s3) PutObject(ctx context.Context, bucketName, key string, meta map[string]string, input io.Reader, size int64) (gofakes3.PutObjectResult, error) {
opts := api.UploadObjectOptions{}
opts := api.UploadObjectOptions{
Size: size,
}
if ct, ok := meta["Content-Type"]; ok {
opts.MimeType = ct
}
Expand Down Expand Up @@ -403,6 +405,7 @@ func (s *s3) CreateMultipartUpload(ctx context.Context, bucket, key string, meta
func (s *s3) UploadPart(ctx context.Context, bucket, object string, id gofakes3.UploadID, partNumber int, contentLength int64, input io.Reader) (*gofakes3.UploadPartResult, error) {
res, err := s.w.UploadMultipartUploadPart(ctx, input, bucket, object, string(id), partNumber, api.UploadMultipartUploadPartOptions{
DisablePreshardingEncryption: true,
ContentLength: contentLength,
})
if err != nil {
return nil, gofakes3.ErrorMessage(gofakes3.ErrInternal, err.Error())
Expand Down
16 changes: 16 additions & 0 deletions worker/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ func (c *Client) UploadMultipartUploadPart(ctx context.Context, r io.Reader, buc
panic(err)
}
req.SetBasicAuth("", c.c.WithContext(ctx).Password)
if opts.ContentLength != 0 {
req.ContentLength = opts.ContentLength
} else {
if s, ok := r.(io.Seeker); ok {
_, _ = s.Seek(0, io.SeekEnd)
_, _ = s.Seek(0, io.SeekStart)
}
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -225,6 +233,14 @@ func (c *Client) UploadObject(ctx context.Context, r io.Reader, bucket, path str
panic(err)
}
req.SetBasicAuth("", c.c.WithContext(ctx).Password)
if opts.Size != 0 {
req.ContentLength = opts.Size
} else {
if s, ok := r.(io.Seeker); ok {
_, _ = s.Seek(0, io.SeekEnd)
_, _ = s.Seek(0, io.SeekStart)
}
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
Expand Down