Open bruce-hill opened 3 months ago
As a workaround, url.split("#")[0]
should get the job done to strip the fragment part of the URL.
I faced the same issue about two weeks ago, being struggling with it until found the root cause today and surprised that it'll be solved. Just wanted to say that it can lead to potential issues in future. I think, most web servers (at least Google's one) can handle this fragment part and process or just ignore it. Imagine you had a link www.abc.com/qwe#asd, then it was moved to www.abc.com/qwert#asdfg and you want to apply a 301 redirect to it. If the HTTPRequest
will ignore the fragment part, it'll not be able to follow the redirect link properly. Despite this issue, it is better to ignore it since some of the web servers will just respond with the 400 status code when find the number sign in URI.
Tested versions
System information
Windows 10
Issue description
If you make an HTTP request in Godot using a URL that contains a URI Fragment, Godot does not give any error messages and creates an HTTP request that includes the URI fragment, which is not supposed to be sent to the server. Many servers will not accept requests sent to paths that include a fragment and will return a 400 or 404 response. The correct behavior should be to strip the fragment out of the URL, which is what tools like cURL do.
Steps to reproduce
HTTPRequest.request(url)
with a URL that has#whatever
at the end.To verify this locally, I ran netcat (
nc -lk 12345
) and made a request to$HTTPRequest.request("http://127.0.0.1:12345/page#fragment")
. The netcat output was:For comparison, HTTP requests sent by curl do not include the fragment:
curl 'http://127.0.0.1:12345/page#fragment
Minimal reproduction project (MRP)
HTTPFragmentIssue.zip