You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you change the scheme from a non-relative one to a relative one without regenerating the scheme data, the Url object stops working properly. For example, parsing view-source+http://google.com and then using slice() on url.scheme to make it http again does not change the corresponding scheme data.
Perhaps there should be a set_scheme() method for setting the scheme safely?
This same issue affects some of the upcoming HSTS code in servo where a Url is changed from http to https.
If it's not reasonable to mutate the scheme, does it make more sense to make scheme private and require a function call to read it? This way you can't create a Url instance that has an invalid state.
@samfoohttp and https are both "relative" schemes, though. What’s the problem you’re seeing with HSTS? It might not be the same as the original issue here.
A simple test case is probably the easiest way to show one of the problems (that the default port doesn't change). This is specifically the problem with the pull request for HSTS. I'm not sure how much other internal state the Url keeps that could potentially cause a problem.
Is the best I could come up with, since default_port is on the the scheme data, not the Url. But that is better than serialising and re-parsing which is the strategy I took up 'til now.
Activity
SimonSapin commentedon Dec 17, 2014
I’m a bit reluctant, since it’s not obvious what the semantics of changing the scheme like this should be.
For the case of
view-source+specifically, I wonder if you wouldn’t be better detecting and off cutting of the prefix before parsing as an URL.samfoo commentedon Jul 19, 2015
This same issue affects some of the upcoming HSTS code in servo where a
Urlis changed from http to https.If it's not reasonable to mutate the scheme, does it make more sense to make
schemeprivate and require a function call to read it? This way you can't create aUrlinstance that has an invalid state.SimonSapin commentedon Jul 19, 2015
@samfoo
httpandhttpsare both "relative" schemes, though. What’s the problem you’re seeing with HSTS? It might not be the same as the original issue here.samfoo commentedon Jul 19, 2015
A simple test case is probably the easiest way to show one of the problems (that the default port doesn't change). This is specifically the problem with the pull request for HSTS. I'm not sure how much other internal state the
Urlkeeps that could potentially cause a problem.SimonSapin commentedon Jul 19, 2015
I’m thinking of refactoring the parser and data structure to fix a bunch of things including this.
But in the mean time, you can work around this issue by using
url.defaul_port = Some(443)when changing the scheme to HTTPS.samfoo commentedon Jul 19, 2015
Is the best I could come up with, since
default_portis on the the scheme data, not theUrl. But that is better than serialising and re-parsing which is the strategy I took up 'til now.Uses the approach suggested by @SimonSapin for changing Url scheme
SimonSapin commentedon Jul 19, 2015
Yes, I think this is the best we can do without changing the data structure. There could be a
set_schememethod, but it’d just do this internally.Uses the approach suggested by @SimonSapin for changing Url scheme
Uses the approach suggested by @SimonSapin for changing Url scheme
Add a test default port number when changing scheme.
Add a test default port number when changing scheme.
Add a test default port number when changing scheme.
Add a test default port number when changing scheme.
SimonSapin commentedon Apr 21, 2016
This passes in 1.0:
#187 adds it as a test case.