Skip to content

Commit

Permalink
fix(gateway)!: no duplicate payload during subdomain redirects (#9913)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
hacdias and lidel committed Jun 2, 2023
1 parent 6eef0b4 commit eb265f7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
22 changes: 20 additions & 2 deletions docs/changelogs/v0.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
- [Overview](#overview)
- [🔦 Highlights](#-highlights)
- [Saving previously seen nodes for later bootstrapping](#saving-previously-seen-nodes-for-later-bootstrapping)
- [`Gateway.DeserializedResponses` config flag](#gatewaydeserializedresponses-config-flag)
- [Gateway: `DeserializedResponses` config flag](#gateway-deserializedresponses-config-flag)
- [`client/rpc` migration of `go-ipfs-http-client`](#clientrpc-migration-of-go-ipfs-http-client)
- [Gateway: DAG-CBOR/-JSON previews and improved error pages](#gateway-dag-cbor-json-previews-and-improved-error-pages)
- [Gateway: subdomain redirects are now `text/html`](#gateway-subdomain-redirects-are-now-texthtml)
- [📝 Changelog](#-changelog)
- [👨‍👩‍👧‍👦 Contributors](#-contributors)

Expand All @@ -32,7 +33,7 @@ enabled.
With this update, the same level of robustness is applied to peers that lack
mDNS peers and solely rely on the public DHT.

#### `Gateway.DeserializedResponses` config flag
#### Gateway: `DeserializedResponses` config flag

This release introduces the
[`Gateway.DeserializedResponses`](https://github.com/ipfs/kubo/blob/master/docs/config.md#gatewaydeserializedresponses)
Expand Down Expand Up @@ -84,6 +85,23 @@ HTML responses are returned when request's `Accept` header includes `text/html`.
| ---- | ---- |
| ![DAG-CBOR Preview](https://github.com/ipfs/boxo/assets/5447088/973f05d1-5731-4469-9da5-d1d776891899) | ![Error Page](https://github.com/ipfs/boxo/assets/5447088/14c453df-adbc-4634-b038-133121914550) |

#### Gateway: subdomain redirects are now `text/html`

HTTP 301 redirects [from path to subdomain](https://specs.ipfs.tech/http-gateways/subdomain-gateway/#migrating-from-path-to-subdomain-gateway)
no longer include the target data in the body.
The data is returned only once, with the final HTTP 200 returned from the
target subdomain.

The HTTP 301 body now includes human-readable `text/html` message
for clients that do not follow redirects by default:

```console
$ curl "https://subdomain-gw.example.net/ipfs/${cid}/"
<a href="http://${cid}.ipfs.subdomain-gw.example.net/">Moved Permanently</a>.
```

Rationale can be found in [kubo#9913](https://github.com/ipfs/kubo/pull/9913).

### 📝 Changelog

### 👨‍👩‍👧‍👦 Contributors
2 changes: 1 addition & 1 deletion docs/examples/kubo-as-a-library/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.18
replace github.com/ipfs/kubo => ./../../..

require (
github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076
github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
github.com/libp2p/go-libp2p v0.27.3
github.com/multiformats/go-multiaddr v0.9.0
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/kubo-as-a-library/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076 h1:jkmzkt/eRxC+tAOgUYOoQh50Bvfnun/Dy3n72tRSkmo=
github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076/go.mod h1:Ej2r08Z4VIaFKqY08UXMNhwcLf6VekHhK8c+KqA1B9Y=
github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21 h1:efxZK66VVeQ1cGczX7ufjd4DW6X2nb/PbAJ5k85YC98=
github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21/go.mod h1:Ej2r08Z4VIaFKqY08UXMNhwcLf6VekHhK8c+KqA1B9Y=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/google/uuid v1.3.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076
github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21
github.com/ipfs/go-block-format v0.1.2
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-cidutil v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076 h1:jkmzkt/eRxC+tAOgUYOoQh50Bvfnun/Dy3n72tRSkmo=
github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076/go.mod h1:Ej2r08Z4VIaFKqY08UXMNhwcLf6VekHhK8c+KqA1B9Y=
github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21 h1:efxZK66VVeQ1cGczX7ufjd4DW6X2nb/PbAJ5k85YC98=
github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21/go.mod h1:Ej2r08Z4VIaFKqY08UXMNhwcLf6VekHhK8c+KqA1B9Y=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
Expand Down
10 changes: 4 additions & 6 deletions test/sharness/t0114-gateway-subdomains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,12 @@ test_localhost_gateway_response_should_contain \
"http://localhost:$GWAY_PORT/ipfs/$DIR_CID/" \
"Location: http://$DIR_CID.ipfs.localhost:$GWAY_PORT/"

# We return body with HTTP 301 so existing cli scripts that use path-based
# gateway do not break (curl doesn't auto-redirect without passing -L; wget
# does not span across hostnames by default)
# Context: https://github.com/ipfs/go-ipfs/issues/6975
# We return human-readable body with HTTP 301 so existing cli scripts that use path-based
# gateway are informed to enable following HTTP redirects
test_localhost_gateway_response_should_contain \
"request for localhost/ipfs/{CIDv1} includes valid payload in body for CLI tools like curl" \
"request for localhost/ipfs/{CIDv1} includes human-readable link and redirect info in HTTP 301 body" \
"http://localhost:$GWAY_PORT/ipfs/$CIDv1" \
"$CID_VAL"
">Moved Permanently</a>"

test_localhost_gateway_response_should_contain \
"request for localhost/ipfs/{CIDv0} redirects to CIDv1 representation in subdomain" \
Expand Down

0 comments on commit eb265f7

Please sign in to comment.