-
Notifications
You must be signed in to change notification settings - Fork 7.3k
http.request behavior changed between 0.10.5 and 0.11.2 #5474
Comments
That change was introduced (deliberately) in 38149bb. Rock, hard place: the old behavior makes it easy to create invalid requests but the new behavior is inconvenient and non-intuitive. Maybe I should just revert it and have it throw an error when the path contains illegal characters. Thoughts? |
As a developer I wouldn't rely on any validity parsing, all it should serve to do is uncover bugs. Additionally consider developers may want to send invalid requests. I wouldn't do validity checking for this reason. If the "path" is checked for validity, keep in mind that there's several valid forms; it may be a literal |
Well, the particular case that commit aims to address is paths with spaces in them. Those are never valid because the request line ends up looking like |
Perhaps this: If it's a Buffer, use the value as-is. If it's a string, then it must be unicode, therefore Node.js should apply the IRI-to-URI transformation as specified in RFC 3987 3.1. This transformation is one that will also convert spaces to |
The problem is that you had to escape the URL with versions <= 0.10 because To be backward compatible you should either 1) do nothing, 2) throw if the URL contains spaces, 3) escape only the space chars. I have a slight preference for 2). |
Commit 38149bb changes http.get() and http.request() to escape unsafe characters. However, that creates an incompatibility with v0.10 that is difficult to work around: if you escape the path manually, then in v0.11 it gets escaped twice. Change lib/http.js so it no longer tries to fix up bad request paths, simply reject them with an exception. The actual check is rather basic right now. The full check for illegal characters is difficult to implement efficiently because it requires a few characters of lookahead. That's why it currently only checks for spaces because those are guaranteed to create an invalid request. Fixes nodejs#5474.
Thanks. |
http.request
encodes the URL path in 0.11.2 but not in 0.10.5Repro:
v0.10.5 output:
v0.11.2 output:
If I don't encode the space and set path to
'/abc?foo=bar zoo'
in the request call, I get a crash in v0.10.5 and a success withserver got: /abc?foo=bar%20zoo
in v0.11.2.The text was updated successfully, but these errors were encountered: