Skip to content

Conversation

@gammazero
Copy link
Contributor

@gammazero gammazero commented Nov 20, 2025

Add the ability to explicitly set the response emitter encoding type.

This is used to set the encoding type of the response emitter to something other than the default. For example, when setting the encoding type to Gzip when compressed output is being emitted.

Needed for:

I do not know if this is the right way to do this, but testing with kubo PR above indicates it does work.

TODO: add unit test to check HTTP headers

Add the ability to explicitly set the response emitter encoding type.

This is used to set the encoding type of the response emitter to something other than the default. For example, when setting the encoding type to `Gzip` when compressed output is being emitted.

Needed for: ipfs/kubo#2376
@gammazero gammazero marked this pull request as ready for review December 1, 2025 17:55
@gammazero gammazero added the need/triage Needs initial labeling and prioritization label Dec 1, 2025
lidel added 2 commits January 30, 2026 18:01
- add Tar encoding type with application/x-tar MIME type
- use application/gzip per RFC 6713 (removed non-standard charset=binary
  parameter, which only applies to text/* types)
- keep application/x-gzip as legacy alias for response parsing
- document SetEncodingType interface with usage guidelines
- add tests for Content-Type headers and backward compatibility
replace the Tar and Gzip encoding types with a generic OctetStream
encoding type and add SetContentType() method to ResponseEmitter.

this allows commands to specify custom MIME types for binary data
without needing specific encoding types for each format. commands
can now use:

    res.SetEncodingType(cmds.OctetStream)
    res.SetContentType("application/vnd.ipld.car")

to set any Content-Type header for HTTP responses.

changes:
- remove Tar and Gzip encoding types from encoding.go
- add OctetStream encoding type (application/octet-stream)
- add SetContentType(string) to ResponseEmitter interface
- implement SetContentType in http responseEmitter
- add no-op SetContentType to chan, cli, and writer emitters
- update MIMEEncodings and mimeTypes maps
- update tests for new encoding types
@lidel lidel marked this pull request as draft January 30, 2026 18:55
adds HelpText.HTTP field with HTTPHelpText struct containing:
- ResponseContentType: documents Content-Type header for HTTP responses
- Description: additional HTTP-specific notes shown after Tagline

this enables tools like http-api-docs to generate better API reference
by reading HTTP-specific metadata directly from command definitions.
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the initial implementation!

I adjusted the approach to make it more generic and future-proof. Instead of specific encoding types for each format, we now have:

  1. A generic OctetStream binary response type that uses application/octet-stream
  2. SetContentType() function that allows commands like ipfs get to programmatically adjust the Content-Type header based on runtime conditions (e.g., --compress flag). Wired it and tested in ipfs/kubo#11067 and it works as expected.

This way we don't need to add new encoding types every time we want a different Content-Type, and commands have full control over the header when needed.

The change is backward-compatible and opt-in (existing commands work exactly as before), so merging this as there's no risk shipping it.

@lidel lidel marked this pull request as ready for review January 30, 2026 22:16
@lidel lidel changed the title feature: set ResponseEmitter encoding type feat(http): ability to control Content-Type of binary responses Jan 30, 2026
@lidel lidel merged commit 44581e1 into master Jan 30, 2026
10 checks passed
@lidel lidel deleted the set-encoding-type branch January 30, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need/triage Needs initial labeling and prioritization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants