googleapis / googleapis/storage-testbench

parse_multipart crashes with KeyError when Content-Type header is missing in multipart body part

Open
#801 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
24
Forks
38
Avg merge
1d 15h
Merged PRs (30d)
1

Description

## Bug Description

`parse_multipart` in `testbench/common.py` (line 307) crashes with a `KeyError` when a multipart upload body part does not include a `Content-Type` header.

## Steps to Reproduce

Send a multipart upload request where the media body part omits the `Content-Type` header. This is what the [`google-cloud-storage` Rust crate](https://github.com/yoshidan/google-cloud-rust) does when calling `write_object(...).send_buffered()`.

## Error

```
File "/opt/storage-testbench/testbench/common.py", line 307, in parse_multipart
content_type = {"content-type": headers[content_type_key].decode("utf-8")}
~~~~~~~^^^^^^^^^^^^^^^^^^
KeyError: b'content-type'
```

## Expected Behavior

Per RFC 2046, a missing `Content-Type` in a body part should default to `text/plain` (or `application/octet-stream` for GCS media). The testbench should handle this gracefully rather than crashing.

The real GCS API accepts these uploads without issue.

## Environment

- storage-testbench Docker image: `gcr.io/cloud-devrel-public-resources/storage-testbench:latest` (pulled 2026-05-15)
- Client: `google-cloud-storage` Rust crate (google-cloud-rust)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.