Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/ipfs/kubo/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions docs/changelogs/v0.30.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -129,6 +130,10 @@ Modification time support was also added to the Gateway. If present, value from
> [!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 comman, 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.
gammazero marked this conversation as resolved.
Show resolved Hide resolved

### 📝 Changelog

### 👨‍👩‍👧‍👦 Contributors
6 changes: 5 additions & 1 deletion test/sharness/t0235-cli-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading