Consistently use CreateProxyUri in WebProxy ctors #62338
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WebProxy
hasnew(Uri Address)
,new(string Address)
,new(string Host, int Port)
constructors that all behave differently.The
new(string)
overload will check if the address is an absolute Uri and add a"http://"
prefix otherwise.The
new(string, int)
overload will blindly concat the host and port$"http://{Host}:{Port}"
.If you happen to create a
WebProxy
object likenew WebProxy("socks5://127.0.0.1", 9050)
, what you actually end up with is a proxy to"http://socks5://127.0.0.1:9050"
- an http proxy with the hostsocks5
and a default port.We should either check if the host is already an absolute Uri like we do for other overloads (this PR), or we should throw.
socks5://127.0.0.1
is not a valid host, it just happens to be interpreted as:Host:
socks5
Port:
:
(empty port is allowed and means "default for the scheme")Path:
//127.0.0.1
cc: @ManickaP who noticed our blog posts announcing
socks
support have broken code snippets.