googleapis / googleapis/google-cloud-java

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

未关闭
#12,631 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
api: storage
主要语言
Java
星标
2.1k
派生
1.2k
平均合并
1 天 23 小时
30 天内合并 PR
157

描述

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.

贡献指南

打开贡献指南

调研方向

从 issue 中显示的 Java Storage.create 方法开始,跟踪 multipart upload 请求是如何组装的。使用已知的字节数组大小重现该请求,然后验证对象正文部分包含 Content-Length 标头,并为受影响的 create 路径添加覆盖测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
gcp, java
领域
api, cloud
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。