Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added support for scheme-relative URLs. #7

Merged
merged 1 commit into from

2 participants

@ptaoussanis
  • Modified core/absolute-url?.
  • Added core/route-compile lex rule.
  • Added example to README.
  • Added corresponding unit test.
  • All tests passing: new and old.

Signed-off-by: Peter Taoussanis ptaoussanis@gmail.com

Peter Taoussanis Added support for scheme-relative URLs.
* Modified core/absolute-url?.
* Added core/route-compile lex rule.
* Added example to README.
* Added corresponding unit test.
* All tests passing: new and old.

Signed-off-by: Peter Taoussanis <p.taoussanis@gmail.com>
403e555
@weavejester
Owner

This is pretty much exactly what I had in mind.

@weavejester weavejester reopened this
@weavejester
Owner

I hope Github didn't eat the merge...

@weavejester weavejester reopened this
@weavejester
Owner

It looks like Github screwed up. I'll try and merge it manually.

@weavejester weavejester merged commit ac93602 into weavejester:master
@weavejester
Owner

Okay, looks like it's worked now :)

@ptaoussanis

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 22, 2012
  1. Added support for scheme-relative URLs.

    Peter Taoussanis authored
    * Modified core/absolute-url?.
    * Added core/route-compile lex rule.
    * Added example to README.
    * Added corresponding unit test.
    * All tests passing: new and old.
    
    Signed-off-by: Peter Taoussanis <p.taoussanis@gmail.com>
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 3 deletions.
  1. +9 −0 README.md
  2. +3 −2 src/clout/core.clj
  3. +11 −1 test/clout/test/core.clj
View
9 README.md
@@ -33,6 +33,15 @@ Clout can also match absolute routes:
(request :get "http://subdomain.example.com/"))
{}
+And scheme-relative routes:
+
+ user=> (route-matches "//subdomain.example.com/"
+ (request :get "http://subdomain.example.com/"))
+ {}
+ user=> (route-matches "//subdomain.example.com/"
+ (request :get "https://subdomain.example.com/"))
+ {}
+
Clout supports both keywords and wildcards. Keywords (like ":title") will
match any character but the following: `/ . , ; ?`. Wildcards (*) will match
anything.
View
5 src/clout/core.clj
@@ -111,9 +111,9 @@
(recur results src clauses))))))
(defn- absolute-url?
- "True if the path contains an absolute URL."
+ "True if the path contains an absolute or scheme-relative URL."
[path]
- (boolean (re-matches #"https?://.*" path)))
+ (boolean (re-matches #"(https?:)?//.*" path)))
(defn route-compile
"Compile a path string using the routes syntax into a uri-matcher struct."
@@ -130,6 +130,7 @@
(apply str
(lex path
splat "(.*?)"
+ #"^//" "https?://"
word #(str "(" (word-regex %) ")")
literal #(re-escape (.group %)))))
(remove nil?
View
12 test/clout/test/core.clj
@@ -74,7 +74,17 @@
"http://localhost/"
{:scheme :http
:headers {"host" "localhost"}
- :uri "/"})))
+ :uri "/"}))
+ (is (route-matches
+ "//localhost/"
+ {:scheme :http
+ :headers {"host" "localhost"}
+ :uri "/"}))
+ (is (route-matches
+ "//localhost/"
+ {:scheme :https
+ :headers {"host" "localhost"}
+ :uri "/"})))
(deftest url-port-paths
(let [req (request :get "http://localhost:8080/")]
Something went wrong with that request. Please try again.