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 件 担当者 0 名 GitHub で見る
api: storage
主要言語
Java
スター
2.1k
フォーク
1.2k
平均マージ
1日 23時間
マージ済み PR(30日)
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.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start at the Java Storage.create methods shown in the issue and trace how the multipart upload request is assembled. Reproduce the request with a known byte-array size, then verify that the object body part includes a Content-Length header and add coverage for the affected create path.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
gcp, java
領域
api, cloud
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。