Repository navigation
fix(http): add default Content-Type for non-empty HTTP::Tiny bodies (GH-1678) - #1699
Merged
Merged
Conversation
…bodies (GH-1678) System HTTP::Tiny sends `Content-Type: application/octet-stream` when a non-empty scalar is supplied as `content` and the caller does not supply a content-type header (_prepare_headers_and_cb lines 819/832). The Java-backed HTTP::Tiny shim omitted this default, causing servers to return different responses. MetaCPAN's reverse-dependencies endpoint returned a Latin-1 encoded body instead of UTF-8 JSON, which broke JSON decoding in MetaCPAN::Client tests (t/api/author.t, t/api/reverse-dependencies.t). Changes: - HttpTiny.java: before forwarding caller headers, check case-insensitively whether a content-type was supplied; if not and the body is non-empty, inject `Content-Type: application/octet-stream`, matching Perl HTTP::Tiny exactly. - HttpTinyBinaryResponseTest.java: three new @tag("unit") tests using a local HttpServer that records incoming request headers: requestAddsDefaultContentTypeForNonEmptyBody requestPreservesCallerSuppliedContentType requestDoesNotAddContentTypeForEmptyBody Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PerlOnJava's Java-backed
HTTP::Tinywas omitting theContent-Type: application/octet-streamdefault header that systemHTTP::Tinyadds for non-empty scalar request bodies without a caller-supplied content type (_prepare_headers_and_cblines 819/832).This caused servers to return different responses. MetaCPAN's reverse-dependencies endpoint returned a Latin-1 encoded body instead of UTF-8 JSON, breaking JSON decoding in MetaCPAN::Client tests.
Changes
HttpTiny.java: After settingUser-Agentand before forwarding caller headers, check case-insensitively whether the caller supplied acontent-type. If not, and the body is non-empty, injectContent-Type: application/octet-stream— matching PerlHTTP::Tinyexactly.HttpTinyBinaryResponseTest.java: Three new@Tag("unit")regression tests using a localHttpServerthat captures incoming request headers:requestAddsDefaultContentTypeForNonEmptyBody— verifies the default is injectedrequestPreservesCallerSuppliedContentType— verifies caller content-type is not overriddenrequestDoesNotAddContentTypeForEmptyBody— verifies no content-type on empty bodyTest plan
HttpTinyBinaryResponseTesttests pass (including 3 new ones)makepasses (full unit test suite green)Fixes #1678
🤖 Generated with Claude Code