Skip to content

fix(http): add default Content-Type for non-empty HTTP::Tiny bodies (GH-1678) - #1699

Merged
fglock merged 1 commit into
masterfrom
fix/1678-http-tiny-default-content-type
Oct 8, 2026
Merged

fglock merged 1 commit into
masterfrom
fix/1678-http-tiny-default-content-type

Conversation

@fglock

@fglock fglock commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Summary

PerlOnJava's Java-backed HTTP::Tiny was omitting the Content-Type: application/octet-stream default header that system HTTP::Tiny adds for non-empty scalar request bodies without a caller-supplied content type (_prepare_headers_and_cb lines 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 setting User-Agent and before forwarding caller headers, check case-insensitively whether the caller supplied a content-type. 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") regression tests using a local HttpServer that captures incoming request headers:

    • requestAddsDefaultContentTypeForNonEmptyBody — verifies the default is injected
    • requestPreservesCallerSuppliedContentType — verifies caller content-type is not overridden
    • requestDoesNotAddContentTypeForEmptyBody — verifies no content-type on empty body

Test plan

  • All four HttpTinyBinaryResponseTest tests pass (including 3 new ones)
  • make passes (full unit test suite green)

Fixes #1678

🤖 Generated with Claude Code

…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>
@fglock
fglock merged commit fc73e76 into master Oct 8, 2026
2 checks passed
@fglock
fglock deleted the fix/1678-http-tiny-default-content-type branch October 8, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP::Tiny omits default Content-Type for scalar request bodies

1 participant