googleapis / googleapis/google-cloud-java

[java-storage] Storage.create methods don't set `content-length` header even if the size is known

Đang mở
#12,631 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
api: storage
Ngôn ngữ chính
Java
Star
2.1k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
154

Mô tả

I was looking at the underlying HTTP requests made by this program:
```java
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.StorageOptions;
import java.util.logging.Level;
import java.util.logging.Logger;

class X {
private static final String BUCKET_NAME = "mybucket";

public static void main(String[] args) throws Exception {
Logger.getLogger("com.google.api.client.http").setLevel(Level.ALL);
Logger.getLogger("").getHandlers()[0].setLevel(Level.ALL);
try (var s = StorageOptions.getDefaultInstance().getService()) {
var b = BlobId.of(BUCKET_NAME, "blob");
s.create(
BlobInfo.newBuilder(b).setContentType("text/plain").build(),
"hello world".getBytes(UTF_8));
s.delete(b);
}
}
}
```
The actual object insertion request comes out like this:
```
POST https://storage.googleapis.com/upload/storage/v1/b/mybucket/o?projection=full&uploadType=multipart
Accept-Encoding: gzip
Authorization: Bearer redacted
User-Agent: gcloud-java/2.61.0 Google-API-Java-Client/2.7.2 Google-HTTP-Java-Client/2.0.2 (gzip)
x-goog-user-project:
x-goog-api-client: gl-java/21.0.9 gdcl/2.7.2 linux/6.17.0 gccl-invocation-id/2596662c-8ab2-4ff3-8bae-d7859bee9f6c
x-goog-gcs-idempotency-token: 2596662c-8ab2-4ff3-8bae-d7859bee9f6c
Content-Type: multipart/related; boundary=__END_OF_PART__3a425b6d-f309-4ccf-99cd-3a84be601630__
Content-Encoding: gzip

boundary=__END_OF_PART__3a425b6d-f309-4ccf-99cd-3a84be601630__' -H 'Content-Encoding: gzip' -d '@-' -- 'https://storage.googleapis.com/upload/storage/v1/b/mybucket/o?projection=full&uploadType=multipart' << $$$
Jan 12, 2026 4:12:05 PM com.google.api.client.util.LoggingByteArrayOutputStream close
CONFIG: Total: 449 bytes
Jan 12, 2026 4:12:05 PM com.google.api.client.util.LoggingByteArrayOutputStream close
CONFIG: --__END_OF_PART__3a425b6d-f309-4ccf-99cd-3a84be601630__
Content-Length: 94
Content-Type: application/json; charset=UTF-8
content-transfer-encoding: binary

{"bucket":"mybucket","contentType":"text/plain","crc32c":"yZRlqg==","name":"blob"}
--__END_OF_PART__3a425b6d-f309-4ccf-99cd-3a84be601630__
Content-Type: text/plain
content-transfer-encoding: binary

hello world
--__END_OF_PART__3a425b6d-f309-4ccf-99cd-3a84be601630__--
```

I noticed that the object body part doesn't include a `Content-Length` header even though that is known to the storage SDK.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.