rails/rails — Issue #3856: Problem with network path references (//host.com/uri/scheme)
Author: Overbryd
Created: 2011-12-05 09:32:10+00:00
State: open

Hello,

I file this issue because I do not know the reason why Rails doesn't respect **network path references** that are defined in [RFC3986 Section 4.2](http://tools.ietf.org/html/rfc3986#section-4.2).

**Example** `//asset.host.com/resources/12345`

There is also a good [StackOverflow discussion](http://stackoverflow.com/questions/743247/types-of-urls/743322) about those URLs.
We use this url scheme to build protocol agnostic urls that just work for both *http* and *https*. Since in our special case we cannot reliably determine if https is used, we prefer this way.
The second reason is that we avoid all mixed content warnings, if https is used and resources from our application are being referenced.

But it fails when I use Rails' `redirect_to` method. The reason is clear, because only protocol specific urls are being recognized by [the redirect_to method internals](https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/redirecting.rb#L84)

If we want to `redirect_to "//asset.host.com/resources/12345"` Rails redirects to `http://application.host.com//asset.host.com/resources/12345`.

Now I'm only some keystrokes away from fixing this problem in the Rails core, but before I start I'd like to know why Rails works this way. **Is there a specific reason for this behaviour?**