|
| 1 | +--- |
| 2 | +title: "IPIP-0523: Prefer format request param over Accept header" |
| 3 | +date: 2025-11-26 |
| 4 | +ipip: proposal |
| 5 | +editors: |
| 6 | + - name: Alex Potsides |
| 7 | + github: achingbrain |
| 8 | + url: https://achingbrain.net |
| 9 | + affiliation: |
| 10 | + name: Shipyard |
| 11 | + url: https://ipshipyard.com |
| 12 | +relatedIssues: |
| 13 | + - https://github.com/ipfs/specs/issues/521 |
| 14 | +order: 523 |
| 15 | +tags: ['ipips'] |
| 16 | +--- |
| 17 | + |
| 18 | +## Summary |
| 19 | + |
| 20 | +Prefer the `format` request param over the Accept header |
| 21 | + |
| 22 | +## Motivation |
| 23 | + |
| 24 | +The [Accept](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept) |
| 25 | +header can be sent with an HTTP request to provide a prioritized list of |
| 26 | +response formats the client will accept for a given resource. |
| 27 | + |
| 28 | +The [format](https://specs.ipfs.tech/http-gateways/path-gateway/#format-request-query-parameter) |
| 29 | +request query parameter can also be sent to an IPFS HTTP Gateway to provide the |
| 30 | +same information, and is typically done when sending an HTTP header is difficult |
| 31 | +or impractical, for example in a browser. |
| 32 | + |
| 33 | +The existing [Path Gateway](https://specs.ipfs.tech/http-gateways/path-gateway/#format-request-query-parameter) and [Trustless Gateway](https://specs.ipfs.tech/http-gateways/trustless-gateway/#format-request-query-parameter) specs say: |
| 34 | + |
| 35 | +> When both the Accept header and format parameter are present, a specific Accept value (e.g., application/vnd.ipld.raw) SHOULD take precedence over format. |
| 36 | +
|
| 37 | +This makes it impossible for browsers to use the `format` request query |
| 38 | +parameter, since they will always send an `Accept` header which would then cause |
| 39 | +the `format` request query parameter to be ignored. |
| 40 | + |
| 41 | +## Detailed design |
| 42 | + |
| 43 | +The priority of `format` vs `Accept` should be reversed, so as to always prefer |
| 44 | +`format` over `Accept` if it is present. |
| 45 | + |
| 46 | +## Design rationale |
| 47 | + |
| 48 | +Browsers will always send an `Accept` header that contains specific values so it |
| 49 | +cannot be allowed to take priority over the `format` request query parameter. |
| 50 | + |
| 51 | +### User benefit |
| 52 | + |
| 53 | +Users will be able to use the `format` request query parameter to control the |
| 54 | +response type of requests made from browser address bars. |
| 55 | + |
| 56 | +### Compatibility |
| 57 | + |
| 58 | +This is a breaking change, though several implementations implement this part of |
| 59 | +the spec incorrectly, already favouring `format` over `Accept` so the impact |
| 60 | +should be minimal. |
| 61 | + |
| 62 | +### Security |
| 63 | + |
| 64 | +It is highly advised to implement validation conformance tests using the fixtures |
| 65 | +included at the end of this IPIP. |
| 66 | + |
| 67 | +### Alternatives |
| 68 | + |
| 69 | +None. |
| 70 | + |
| 71 | +## Test fixtures |
| 72 | + |
| 73 | +:::note |
| 74 | + |
| 75 | +Implementers can either write own test that prefers the format query param over |
| 76 | +any present Accept header, or run the [gateway-conformance](https://github.com/ipfs/gateway-conformance/) |
| 77 | +test suite, which includes tests for this scenario since [gateway-conformance/pull/252](https://github.com/ipfs/gateway-conformance/pull/252). |
| 78 | + |
| 79 | +::: |
| 80 | + |
| 81 | +### Copyright |
| 82 | + |
| 83 | +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
0 commit comments