Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Cannot add Content-Length header to a multipart part

Open Beginner friendly
#9,814 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@alexzargarian23 is already working on this.

Since Oct 24, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
kotlin

Research direction

Start with MultipartBody.Part.create and the Content-Length require check quoted in the issue, then inspect nearby multipart tests. Confirm how manually supplied part headers are handled for multipart types such as multipart/mixed. Done means the factory accepts the header where permitted, with tests covering the behavior.

Written by the indexing model from the issue text.

Description

bug

In #7319 the Content-Length header ceased being auto-included in every multipart part. That is fine, but manually adding that header to a part throws an exception:

MultipartBody.Part.create(
    headers = Headers.Builder().add("Content-Length", TEST_DATA.size.toString()).build(),
    body = TEST_DATA.toRequestBody(),
) // crash - "Unexpected header: Content-Length"

The crash is due to this line in the MultipartBody.Part.create method:

require(headers?.get("Content-Length") == null) { "Unexpected header: Content-Length" }

I think that require was added because that header was being auto-included at the time. Since that is no longer the case but the require still exists, it's impossible to add a Content-Length header using the factory method.

I believe including Content-Length on a multipart part is out-of-spec if the request is of type multipart/form-data, but is within RFC specs for other types like multipart/mixed.

Tests showing it's not possible to manually include Content-Length: https://gist.github.com/jasonrobinson-gpsw/830a56b81be94a704fad9409d8326865

Dominant language
Kotlin
Stars
47.1k
Forks
9.3k
Avg merge
1d 16h
Merged PRs (30d)
31

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lysine-dev/okhttp

All issues in lysine-dev/okhttp

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.