NSURLConnection, rails, apache, spaces in URLs and "Your browser sent a request that this server could not understand"
My Rails application uses redirect_to at one point in my code where it redirects to a pdf document on an apache server. The URL that it redirects to contains spaces. URLs may not contain spaces. redirect_to does not escape these spaces, but issues a ‘302 Found’ redirect response with the unescaped URL.
When my Cocoa application receives this redirect request through the currently running NSURLConnection, it follows the new url. In 10.4, it escaped the URL before sending the GET request. In 10.5, this is no longer the case, and apache (correctly) barfs on the request with
Bad RequestThe solution is simple: URI::escape the URL before redirecting to it. The big question however, is: Is this a bug in my code, in Rails, or in Cocoa?Your browser sent a request that this server could not understand.
The request line contained invalid characters following the protocol string.
I’m guessing first or second; I’m supposing there’s a very good reason why Apple chose to change the behaviour of NSURLConnection. Also, the Rails documentation does say, String starting with protocol:// (like http://): Is passed straight through as the target for redirection
, which would put the responsibility square on me. However, Rails is generating an invalid response, so I’ll go with blaming rails.