“Using Relative URL Protocol Schemes” or “One Less Special Case for IE”

So the other day I was perusing through some of the RFCs, and came across RFC 1808. It’s called “Relative Uniform Resource Locators.” Of particular interest is section 2.4.3, “Parsing the Network Location/Login,” which says something like:

“Hey, remember the last time you were creating a web application that needed to run in both HTTP and HTTPS? Remember how you had to write logic to detect the current request’s scheme, because you had to generate URLs as https:// when you were secure? Remember that you never thought there was a problem until Jimmy in Marketing looked at your site in Internet Explorer 5.5, and he said to your boss, ‘It says, “Are you sure you want to display insecure items?”, what’s that mean?’

Yeah, you don’t have to do that anymore.”

The problem is essentially this:

When you’re creating a link on a page that may be viewed securely (https://site.com/page.html), you have to change the protocol of the link to match the scheme you’re using. If you don’t, people using Internet Explorer get a dialog box in their face every time they load the page.

The usual method for fixing this is to add logic to your application which finds out (using various methods) whether the page is being accessed securely (https://) or insecurely (http://), and generates an appropriate prefix. You then take this prefix and stuff it in front of every generated link.

RFC 1808 § 2.4.3 says basically, just leave off scheme: from your url, and the web browser will figure it out for you.

Instead of writing your links like this:

    def make_url(url):
        if do_magic_to_see_if_we_are_secure(): 
            scheme = "https://"
        else:
            scheme = "http://"
        return scheme + url
    print make_url("site.com/page.html")

All you have to do is this:

    url = "//site.com/page.html"

Now when you go to https://site.com, your link becomes “https://site.com/page.html”.

When you go to http://site.com, your link becomes “http://site.com/page.html”.

Done. No code. One less special case for IE.

Advertisements

,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: