Skip to content

Omit the default port from the logged URL - #188

Open
tycooon wants to merge 1 commit into
trusche:masterfrom
zapravila-org:omit-default-port-in-logged-url
Open

tycooon wants to merge 1 commit into
trusche:masterfrom
zapravila-org:omit-default-port-in-logged-url

Conversation

@tycooon

@tycooon tycooon commented Sep 19, 2026

Copy link
Copy Markdown

Follow-up to the scheme fix already on master: an ordinary HTTPS request is still logged as

https://example.com:443/foo/bar

That is not the URL anyone writes by hand, which costs twice in practice — grepping a log for the URL a client actually uses finds nothing, and the line cannot be pasted into curl as it stands.

This drops the port when it is the default for the scheme, and keeps it otherwise:

https://example.com/foo/bar       # was https://example.com:443/foo/bar
http://example.com/foo/bar        # was http://example.com:80/foo/bar
http://example.com:9292/foo/bar   # unchanged
https://example.com:8443/foo/bar  # unchanged

This is what #63 was after. You said there you were happy to merge it with passing specs, so this branch brings them.

Specs

The suite's server listens on 9292, a non-default port, so no existing expectation moves. The new spec drives Net::HTTP directly rather than through the test server, since the ports that matter here are 443 and 80, and covers all four cases above.

I ran the full suite before and after the change on Ruby 3.4.5: same 169 failures either way (colour and Excon/Oj expectations that fail on master in my environment), plus the 4 new passing examples. So nothing here regresses.

Note for anyone filtering on the URL

url_approved? matches against this same string, so an allowlist or denylist pinned to the literal :443 would need loosening. Patterns that key on the host, or that already treat the scheme and port as optional, are unaffected.

The Net::HTTP adapter always spelled the port out, so an ordinary HTTPS
request was logged as https://example.com:443/path. That is not the URL
anyone writes by hand, so grepping the log for the URL a gateway uses
finds nothing, and the line cannot be pasted into curl as it stands.

Dropped when it is the default for the scheme, keeping any other port.
The suite's own server listens on 9292, so the existing expectations are
unaffected; the new spec drives Net::HTTP directly to cover 443 and 80.
@tycooon
tycooon requested a review from trusche as a code owner September 19, 2026 07:41

@trusche trusche left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @tycooon, good improvement!

  • connect also uses url_approved? and would have to be modified for consistency
  • While we're at it, excon.rb:7 is the last remaining place forcing the port unconditionally, would you mind fixing that too? Plus the README

end

def connect
HttpLog.log_connection(@address, @port) if !started? && HttpLog.url_approved?("#{@address}:#{@port}")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
HttpLog.log_connection(@address, @port) if !started? && HttpLog.url_approved?("#{protocol}://#{@address}#{port_suffix}")

Let's make sure this is consistent, can we add a spec for this if one doesn't already exist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants