diff --git a/cmd/ipfs/kubo/start.go b/cmd/ipfs/kubo/start.go index cae1e2c1b70..474045e7102 100644 --- a/cmd/ipfs/kubo/start.go +++ b/cmd/ipfs/kubo/start.go @@ -303,7 +303,10 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) { } // Resolve the API addr. - apiAddr, err = resolveAddr(req.Context, apiAddr) + // + // Do not replace apiAddr with the resolved addr so that the requested + // hostname is kept for use in the request's HTTP header. + _, err = resolveAddr(req.Context, apiAddr) if err != nil { return nil, err } diff --git a/docs/changelogs/v0.30.md b/docs/changelogs/v0.30.md index 6cc212f7a8b..d73860971ab 100644 --- a/docs/changelogs/v0.30.md +++ b/docs/changelogs/v0.30.md @@ -13,6 +13,7 @@ - [`/unix/` socket support in `Addresses.API`](#unix-socket-support-in-addressesapi) - [Cleaned Up `ipfs daemon` Startup Log](#cleaned-up-ipfs-daemon-startup-log) - [UnixFS 1.5: Mode and Modification Time Support](#unixfs-15-mode-and-modification-time-support) + - [Commands Preserve Specified Hostname](#commands-preserve-specified-hostname) - [๐Ÿ“ Changelog](#-changelog) - [๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors](#-contributors) @@ -128,6 +129,10 @@ Opt-in support for `mode` and `mtime` was also added to MFS (`ipfs files --help` > [!NOTE] > Storing `mode` and `mtime` requires root block to be `dag-pb` and disabled `raw-leaves` setting to create envelope for storing the metadata. +#### Commands Preserve Specified Hostname + +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//` 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. + ### ๐Ÿ“ Changelog ### ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors diff --git a/test/sharness/t0235-cli-request.sh b/test/sharness/t0235-cli-request.sh index 3b2281894ad..02ef514dedf 100755 --- a/test/sharness/t0235-cli-request.sh +++ b/test/sharness/t0235-cli-request.sh @@ -28,7 +28,7 @@ test_expect_success "start nc" ' ' test_expect_success "can make http request against nc server" ' - ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 & + ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5005 & IPFSPID=$! # handle request for /api/v0/version @@ -80,4 +80,8 @@ test_expect_success "api flag does not appear in request" ' test_expect_code 1 grep "api=/ip4" nc_out ' +test_expect_success "host has dns name not ip address" ' + grep "Host: localhost:5005" nc_out +' + test_done