@cryptotaxi247 / kubo / commits / 5fe960474

fix(cli): preserve hostname specified with --api in http request headers (#10497)

Preserve hostname specified with --api in http request headers - Replaces PR #10233 - Add test to check for hostname in HTTP header - Update docs/changelogs/v0.30.md

Andrew Gillis committed Aug 28, 2024 at 10:03 UTC 5fe960474c4af2c7935839f5e3130dce45af8b63
3 files changed +14 -2
cmd/ipfs/kubo/start.go
+4 -1
@@ -303,7 +303,10 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) {
303 }
304
305 // Resolve the API addr.
306 - apiAddr, err = resolveAddr(req.Context, apiAddr)
306 + //
307 + // Do not replace apiAddr with the resolved addr so that the requested
308 + // hostname is kept for use in the request's HTTP header.
309 + _, err = resolveAddr(req.Context, apiAddr)
310 if err != nil {
311 return nil, err
312 }
docs/changelogs/v0.30.md
+5
@@ -13,6 +13,7 @@
13 - [`/unix/` socket support in `Addresses.API`](#unix-socket-support-in-addressesapi)
14 - [Cleaned Up `ipfs daemon` Startup Log](#cleaned-up-ipfs-daemon-startup-log)
15 - [UnixFS 1.5: Mode and Modification Time Support](#unixfs-15-mode-and-modification-time-support)
16 + - [Commands Preserve Specified Hostname](#commands-preserve-specified-hostname)
17 - [📝 Changelog](#-changelog)
18 - [👨‍👩‍👧‍👦 Contributors](#-contributors)
19
@@ -129,6 +130,10 @@ Modification time support was also added to the Gateway. If present, value from
130 > [!NOTE]
131 > Storing `mode` and `mtime` requires root block to be `dag-pb` and disabled `raw-leaves` setting to create envelope for storing the metadata.
132
133 +#### Commands Preserve Specified Hostname
134 +
135 +When executing a [CLI command](https://docs.ipfs.tech/reference/kubo/cli/) over [Kubo RPC API](https://docs.ipfs.tech/reference/kubo/rpc/), if a hostname is specified by `--api=/dns4/<domain>/` the resulting HTTP request now contains the hostname, instead of the the IP address that the hostname resolved to, as was the previous behavior. This makes it easier for those trying to run Kubo behind a reverse proxy using hostname-based rules.
136 +
137 ### 📝 Changelog
138
139 ### 👨‍👩‍👧‍👦 Contributors
test/sharness/t0235-cli-request.sh
+5 -1
@@ -28,7 +28,7 @@ test_expect_success "start nc" '
28 '
29
30 test_expect_success "can make http request against nc server" '
31 - ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 &
31 + ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005 &
32 IPFSPID=$!
33
34 # handle request for /api/v0/version
@@ -80,4 +80,8 @@ test_expect_success "api flag does not appear in request" '
80 test_expect_code 1 grep "api=/ip4" nc_out
81 '
82
83 +test_expect_success "host has dns name not ip address" '
84 + grep "Host: localhost:5005" nc_out
85 +'
86 +
87 test_done