Bug 264757 - fetch: Show correct port number in -vv output
Summary: fetch: Show correct port number in -vv output
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: easy, needs-qa
Depends on:
Blocks:
 
Reported: 2022-06-18 20:37 UTC by Mallory
Modified: 2024-08-21 10:41 UTC (History)
3 users (show)

See Also:
koobs: maintainer-feedback? (des)
koobs: mfc-stable13?
koobs: mfc-stable12?


Attachments
usr.bin/fetch: Show correct port number in -vv output (1.04 KB, text/plain)
2022-06-18 20:37 UTC, Mallory
no flags Details
usr.bin/fetch: Show correct port number in -vv output (1.13 KB, patch)
2024-08-21 01:31 UTC, Mallory
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mallory 2022-06-18 20:37:34 UTC
Created attachment 234771 [details]
usr.bin/fetch: Show correct port number in -vv output

The code in libfetch only sets the port number in `-vv` output when there's a `:` before the path component. This patch sets the port number based on the URL scheme.

Old behavior:

```
% fetch -vv https://www.freebsd.org/
scheme:   "https"
user:     ""
password: ""
host:     "www.freebsd.org"
port:     "0"
document: "/"
---> www.freebsd.org:443
```

New behavior:

```
% fetch -vv https://www.freebsd.org/
scheme:   "https"
user:     ""
password: ""
host:     "www.freebsd.org"
port:     "443"
document: "/"
---> www.freebsd.org:443
```
Comment 1 Kyle Ambroff-Kao 2024-05-06 00:25:58 UTC
I tried this, and it does work for HTTP and HTTPS URls. But fetch supports other protocols, so a fix for this should work no matter which scheme you use. ftp for example would not be covered by this.
Comment 2 Mallory 2024-08-21 01:31:41 UTC
Created attachment 252969 [details]
usr.bin/fetch: Show correct port number in -vv output

PATCH v2
Comment 3 Kyle Evans freebsd_committer freebsd_triage 2024-08-21 02:20:39 UTC
des probably has more of an opinion on this than I would
Comment 4 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2024-08-21 10:41:30 UTC
I disagree.  It's not the URL parser's place to decide default ports.  And as your own example shows, `fetch -vv` correctly displays the port it connects to regardless.