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
urllib.FancyURLopener does not treat URL fragments correctly #62319
Comments
When urllib.FancyURLopener encounters 302 redirection to a URL with fragments, it sends wrong URL to servers. For example, if we run: Correctly, urllib should strip fragment part of URL before issuing requests. |
Slipped under the radar? |
This is the correct behavior Location is defined in 7.1.2. Location The "Location" header field is used in some responses to refer to a Location = URI-reference The field value consists of a single URI-reference. When it has the A bit after in the spec. If the Location value provided in a 3xx (Redirection) response does For example, a GET request generated for the URI reference
which suggests that the user agent redirect to Likewise, a GET request generated for the URI reference
which suggests that the user agent redirect to |
Hi karl, Of course it is correct that the user agent is redirected to http://example.com/bar#test when it got such response. However, it never means UA can send an HTTP request containing fragment part. In RFC7230 section 3.1.1, HTTP request line is defined as: This means current urllib behavior violates HTTP/1.1 spec. |
Takahashi-san, Ah sorry misunderstood which part your were talking about. I assume wrongly you were talking about navigation. Yes for the request which is sent to the server it should be 1st request:
server response second request must be As for the navigation context is indeed part of the piece of code taking in charge the document after being parsed and not the one doing the HTTP request. (putting it here just that people understand) (to be tested) Recipients of an invalid request-line SHOULD respond with either a |
In class urlopen_HttpTests there is a test for invalid redirects def test_invalid_redirect(self):
https://hg.python.org/cpython/file/4f314dedb84f/Lib/test/test_urllib.py#l247 And one for fragments which refers to http://bugs.python.org/issue11703 code in |
OK I fixed the code. The issue is here newurl = urlunparse(urlparts) Basically it reinjects the fragment in the new url. The fix is easy. if urlparts.fragment:
urlparts = list(urlparts)
urlparts[5] = ""
newurl = urlunparse(urlparts) I was trying to make a test for it, but failed. Could someone help me for the test so I can complete the patch? Added the code patch only. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: