googleapis / googleapis/google-cloud-java

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

Abierto
#12,631 0 comentarios 0 reacciones 0 asignados Ver en GitHub
api: storage
Lenguaje dominante
Java
Estrellas
2.1k
Forks
1.2k
Merge medio
1 d 23 h
PR fusionados (30 d)
154

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.