fixes #408 - It's mostly working, but I added more tests and restructured the
code a bit to handle other schemes correctly.

Review URL: https://chromiumcodereview.appspot.com//12817012