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

Set default proxy ports to spec #717

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

DanGould
Copy link
Contributor

@DanGould DanGould commented Feb 3, 2024

"If the port number is not specified, 80 is always assumed for HTTP."
See: https://www.w3.org/Protocols/HTTP/AsImplemented.html

It was strange behavior to me to default to 8080

@algesten
Copy link
Owner

algesten commented Feb 3, 2024

Hit @DanGould, welcome to ureq!

Is there a spec regarding this for proxies? I don't know why this is 8080 for the proxy. Could just be a mistake.

@DanGould
Copy link
Contributor Author

DanGould commented Feb 3, 2024

Based on some examples [using 8080 in this codebase], I have a feeling it was just a mistake carried over in testing. The RFC that defines HTTP and the CONNECT method says 80 is assumed to be the default. HTTP proxy is just plain http with this method as I understand.

However, curl does default the http proxy to 1080 for "purely historical" reasons, but if the proxy is https (not yet supported by ureq) it defaults to 443 in my experience.

@DanGould
Copy link
Contributor Author

DanGould commented Feb 3, 2024

Looks like SOCKS conventionally listens on port 1080 by spec actually, so I've adjusted the default behavior to match that too

@DanGould DanGould changed the title Set default http proxy port to 80 Set default proxy ports to spec Feb 3, 2024
For HTTP "If the port is empty or not given, port 80 is assumed."
See: https://www.rfc-editor.org/rfc/rfc2616#section-3.2.2

For SOCKS "The SOCKS service is conventionally located on TCP port 1080."
See: https://datatracker.ietf.org/doc/html/rfc1928#section-3
@DanGould
Copy link
Contributor Author

DanGould commented Feb 4, 2024

force pushed to fix clippy lints

@DanGould
Copy link
Contributor Author

DanGould commented Mar 3, 2024

In further testing, I discovered that Url::parse discards the port if it is assumed to be the default port for the scheme. So, for example passing Url::parse(&"http://example.com:80")? to the proxy will strip the port and replace it with 8080 because port is None and before this change port: port.unwrap_or(8080), is called. The only way around this is by passing a Uri without a scheme such as Url::parse(&"example.com:80")?.

The fact that default port numbers are elided by parsing is documented in the Url::port(&self) method docs. "default port numbers are never reflected by the serialization"

I certainly interpret the behavior before the change this PR makes as a bug.

@algesten
Copy link
Owner

So what are we saying the behavior for http://example.com:80 should be with regards to the proxy port?

@DanGould
Copy link
Contributor Author

So what are we saying the behavior for http://example.com:80 should be with regards to the proxy port?

Current behavior

  • an Agent with Proxy::new("http://example.com:80") sends requests to example.com:8080 to be proxied
  • an Agent with Proxy::new("example.com:80") sends requests to example.com:80 to be proxied
  • an Agent with Proxy::new("http://example.com") sends requests to example.com:8080 to be proxied
  • an Agent with Proxy::new("http://example.com:8080") sends requests to example.com:8080 to be proxied

Desired behavior

  • an Agent with Proxy::new("http://example.com:80") sends requests to example.com:80 to be proxied
  • an Agent with Proxy::new("example.com:80") sends requests to example.com:80 to be proxied
  • an Agent with Proxy::new("http://example.com") sends requests to example.com:80 to be proxied
  • an Agent with Proxy::new("http://example.com:8080") sends requests to example.com:8080 to be proxied

@algesten
Copy link
Owner

Alright! This is ready to merge then? Is this a potential breaking change?

@DanGould
Copy link
Contributor Author

Yes. I think this is a breaking change for anyone depending on the 8080 default. That's an odd behavior to depend on but I wouldn't say it's impossible.

@algesten algesten merged commit fce56bb into algesten:main Mar 26, 2024
50 checks passed
@algesten
Copy link
Owner

I think it can be argued that depending on 8080 being the default is not correct behavior.

@DanGould
Copy link
Contributor Author

Thanks for sticking with me and merging this. I think this makes #719 a bit easier so I'll have a revisit to that now

@algesten
Copy link
Owner

Thank you!

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