Skip to content

Conversation

@lidel
Copy link
Member

@lidel lidel commented Dec 3, 2025

Add AllowCodecConversion to gateway.Config to control codec conversion behavior per IPIP-0524. When false (default), the gateway returns 406 Not Acceptable if the requested format doesn't match the block's codec. When true, conversions between codecs are performed for backward compatibility.

Codec conversion tests moved here from gateway-conformance since conversions are now an optional implementation feature, not a spec requirement. Gateway-conformance now tests for 406 responses.

@lidel lidel force-pushed the feat/ipip-0524-optional-codec-conversion branch 3 times, most recently from 5d808bf to 4206b34 Compare December 3, 2025 03:46
@lidel lidel changed the title feat(gateway): add AllowCodecConversion config option feat(gateway): IPIP-0524 + AllowCodecConversion config option Dec 3, 2025
@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.11%. Comparing base (f76a2a7) to head (52a0561).

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1077      +/-   ##
==========================================
+ Coverage   61.09%   61.11%   +0.02%     
==========================================
  Files         264      264              
  Lines       26222    26228       +6     
==========================================
+ Hits        16020    16030      +10     
+ Misses       8524     8520       -4     
  Partials     1678     1678              
Files with missing lines Coverage Δ
gateway/gateway.go 78.08% <ø> (ø)
gateway/handler_codec.go 62.11% <100.00%> (+1.46%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add AllowCodecConversion to gateway.Config to control codec conversion
behavior per IPIP-0524. When false (default), the gateway returns
406 Not Acceptable if the requested format doesn't match the block's
codec. When true, conversions between codecs are performed for backward
compatibility.

Codec conversion tests moved here from gateway-conformance since
conversions are now an optional implementation feature, not a spec
requirement. Gateway-conformance now tests for 406 responses.

Ref: ipfs/specs#524
Ref: ipfs/gateway-conformance#254
@lidel lidel force-pushed the feat/ipip-0524-optional-codec-conversion branch from 4206b34 to c92cc34 Compare December 3, 2025 03:53
Comment on lines +152 to +154
if !i.config.AllowCodecConversion && toCodec != cidCodec {
// Conversion not allowed and codecs don't match - return 406
err := fmt.Errorf("format %q requested but block has codec %q: codec conversion is not supported", rq.responseFormat, cidCodec.String())
Copy link
Member Author

Choose a reason for hiding this comment

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

⚠️ this feels like invasive breaking change, making it impossible to request dag-json as a generic ?format=json or dag-cbor as generic ?format=cbor

If we trully don't allow conversions, these requests will now error on gateways.

I do not know if anyone is using these conversions, so in boxo an kubo I'm going to keep configuration option to opt-in back to old behavior if someone self-hosts.

cc @achingbrain for visibility

lidel added a commit to ipfs/kubo that referenced this pull request Dec 3, 2025
Wire up boxo's AllowCodecConversion config to control codec conversion
behavior per IPIP-0524. When false (default), the gateway returns
406 Not Acceptable if the requested format doesn't match the block's
codec.

Clients should fetch raw blocks (`?format=raw`) and convert client-side.

Ref: ipfs/specs#524
Ref: ipfs/boxo#1077
Ref: ipfs/gateway-conformance#254
lidel added a commit to ipfs/kubo that referenced this pull request Dec 3, 2025
Wire up boxo's AllowCodecConversion config to control codec conversion
behavior per IPIP-0524. When false (default), the gateway returns
406 Not Acceptable if the requested format doesn't match the block's
codec.

Clients should fetch raw blocks (`?format=raw`) and convert client-side.

Ref: ipfs/specs#524
Ref: ipfs/boxo#1077
Ref: ipfs/gateway-conformance#254
lidel added a commit to ipfs/kubo that referenced this pull request Dec 3, 2025
Wire up boxo's AllowCodecConversion config to control codec conversion
behavior per IPIP-0524. When false (default), the gateway returns
406 Not Acceptable if the requested format doesn't match the block's
codec.

Clients should fetch raw blocks (`?format=raw`) and convert client-side.

Ref: ipfs/specs#524
Ref: ipfs/boxo#1077
Ref: ipfs/gateway-conformance#254
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.

2 participants