fix(gateway)!: no duplicate payload during subdomain redirects (#9913)
Co-authored-by: Marcin Rataj <lidel@lidel.org>
Henrique Dias committed
Jun 2, 2023 at 08:14 UTC
eb265f7cd89443f8d9260749377aa2cd6b9d7547
6 files changed
+30
-14
docs/changelogs/v0.21.md
+20
-2
@@ -7,9 +7,10 @@
7
- [Overview](#overview)
8
- [🔦 Highlights](#-highlights)
9
- [Saving previously seen nodes for later bootstrapping](#saving-previously-seen-nodes-for-later-bootstrapping)
10
- - [`Gateway.DeserializedResponses` config flag](#gatewaydeserializedresponses-config-flag)
10
+ - [Gateway: `DeserializedResponses` config flag](#gateway-deserializedresponses-config-flag)
11
- [`client/rpc` migration of `go-ipfs-http-client`](#clientrpc-migration-of-go-ipfs-http-client)
12
- [Gateway: DAG-CBOR/-JSON previews and improved error pages](#gateway-dag-cbor-json-previews-and-improved-error-pages)
13
+ - [Gateway: subdomain redirects are now `text/html`](#gateway-subdomain-redirects-are-now-texthtml)
14
- [📝 Changelog](#-changelog)
15
- [👨👩👧👦 Contributors](#-contributors)
16
@@ -32,7 +33,7 @@ enabled.
33
With this update, the same level of robustness is applied to peers that lack
34
mDNS peers and solely rely on the public DHT.
35
35
-#### `Gateway.DeserializedResponses` config flag
36
+#### Gateway: `DeserializedResponses` config flag
37
38
This release introduces the
39
[`Gateway.DeserializedResponses`](https://github.com/ipfs/kubo/blob/master/docs/config.md#gatewaydeserializedresponses)
@@ -84,6 +85,23 @@ HTML responses are returned when request's `Accept` header includes `text/html`.
85
| ---- | ---- |
86
|  |  |
87
88
+#### Gateway: subdomain redirects are now `text/html`
89
+
90
+HTTP 301 redirects [from path to subdomain](https://specs.ipfs.tech/http-gateways/subdomain-gateway/#migrating-from-path-to-subdomain-gateway)
91
+no longer include the target data in the body.
92
+The data is returned only once, with the final HTTP 200 returned from the
93
+target subdomain.
94
+
95
+The HTTP 301 body now includes human-readable `text/html` message
96
+for clients that do not follow redirects by default:
97
+
98
+```console
99
+$ curl "https://subdomain-gw.example.net/ipfs/${cid}/"
100
+<a href="http://${cid}.ipfs.subdomain-gw.example.net/">Moved Permanently</a>.
101
+```
102
+
103
+Rationale can be found in [kubo#9913](https://github.com/ipfs/kubo/pull/9913).
104
+
105
### 📝 Changelog
106
107
### 👨👩👧👦 Contributors
docs/examples/kubo-as-a-library/go.mod
+1
-1
@@ -7,7 +7,7 @@ go 1.18
7
replace github.com/ipfs/kubo => ./../../..
8
9
require (
10
- github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076
10
+ github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21
11
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
12
github.com/libp2p/go-libp2p v0.27.3
13
github.com/multiformats/go-multiaddr v0.9.0
docs/examples/kubo-as-a-library/go.sum
+2
-2
@@ -321,8 +321,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
321
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
322
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
323
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
324
-github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076 h1:jkmzkt/eRxC+tAOgUYOoQh50Bvfnun/Dy3n72tRSkmo=
325
-github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076/go.mod h1:Ej2r08Z4VIaFKqY08UXMNhwcLf6VekHhK8c+KqA1B9Y=
324
+github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21 h1:efxZK66VVeQ1cGczX7ufjd4DW6X2nb/PbAJ5k85YC98=
325
+github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21/go.mod h1:Ej2r08Z4VIaFKqY08UXMNhwcLf6VekHhK8c+KqA1B9Y=
326
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
327
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
328
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
go.mod
+1
-1
@@ -16,7 +16,7 @@ require (
16
github.com/gogo/protobuf v1.3.2
17
github.com/google/uuid v1.3.0
18
github.com/hashicorp/go-multierror v1.1.1
19
- github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076
19
+ github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21
20
github.com/ipfs/go-block-format v0.1.2
21
github.com/ipfs/go-cid v0.4.1
22
github.com/ipfs/go-cidutil v0.1.0
go.sum
+2
-2
@@ -356,8 +356,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
356
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
357
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
358
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
359
-github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076 h1:jkmzkt/eRxC+tAOgUYOoQh50Bvfnun/Dy3n72tRSkmo=
360
-github.com/ipfs/boxo v0.8.2-0.20230531151409-d1b8d1d6d076/go.mod h1:Ej2r08Z4VIaFKqY08UXMNhwcLf6VekHhK8c+KqA1B9Y=
359
+github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21 h1:efxZK66VVeQ1cGczX7ufjd4DW6X2nb/PbAJ5k85YC98=
360
+github.com/ipfs/boxo v0.8.2-0.20230602025754-4c5c98b94b21/go.mod h1:Ej2r08Z4VIaFKqY08UXMNhwcLf6VekHhK8c+KqA1B9Y=
361
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
362
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
363
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
test/sharness/t0114-gateway-subdomains.sh
+4
-6
@@ -162,14 +162,12 @@ test_localhost_gateway_response_should_contain \
162
"http://localhost:$GWAY_PORT/ipfs/$DIR_CID/" \
163
"Location: http://$DIR_CID.ipfs.localhost:$GWAY_PORT/"
164
165
-# We return body with HTTP 301 so existing cli scripts that use path-based
166
-# gateway do not break (curl doesn't auto-redirect without passing -L; wget
167
-# does not span across hostnames by default)
168
-# Context: https://github.com/ipfs/go-ipfs/issues/6975
165
+# We return human-readable body with HTTP 301 so existing cli scripts that use path-based
166
+# gateway are informed to enable following HTTP redirects
167
test_localhost_gateway_response_should_contain \
170
- "request for localhost/ipfs/{CIDv1} includes valid payload in body for CLI tools like curl" \
168
+ "request for localhost/ipfs/{CIDv1} includes human-readable link and redirect info in HTTP 301 body" \
169
"http://localhost:$GWAY_PORT/ipfs/$CIDv1" \
172
- "$CID_VAL"
170
+ ">Moved Permanently</a>"
171
172
test_localhost_gateway_response_should_contain \
173
"request for localhost/ipfs/{CIDv0} redirects to CIDv1 representation in subdomain" \