feat(gateway): IPIP-0524 + AllowCodecConversion config option#1077
feat(gateway): IPIP-0524 + AllowCodecConversion config option#1077
Conversation
5d808bf to
4206b34
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1077 +/- ##
==========================================
+ Coverage 61.63% 61.68% +0.04%
==========================================
Files 265 265
Lines 26521 26528 +7
==========================================
+ Hits 16347 16363 +16
+ Misses 8487 8479 -8
+ Partials 1687 1686 -1
... and 10 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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
4206b34 to
c92cc34
Compare
gateway/handler_codec.go
Outdated
| 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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I'm assuming this is a niche feature that can go away as long we have meaningful error message in boxo/gateway.
Relaxed spec a bit to allow implementation to handle Accept: application/json in more interoperable way, but that is MAY, not mandatory from spec perspective.
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
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
…al-codec-conversion
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
…al-codec-conversion # Conflicts: # .github/workflows/gateway-conformance.yml # CHANGELOG.md # examples/go.mod
when codec conversion is disabled (IPIP-0524) and you request ?format=dag-json for a dag-pb block, the 406 response now suggests fetching the raw block with ?format=raw and converting client-side. covers dag-pb directories, dag-pb files, and raw blocks requested with ?format=dag-json or ?format=dag-cbor. plain ?format=json and Accept: application/json continue to serve the default response, so existing HTTP clients are not affected.
only show the matching format download link (dag-json or dag-cbor) in the HTML preview page when AllowCodecConversion is disabled, preventing users from clicking links that would return 406. when AllowCodecConversion is enabled, both links are shown as before.
Add
AllowCodecConversiontogateway.Configto 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.