File tree 3 files changed +23
-3
lines changed
3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,15 @@ Clout can also match absolute routes:
33
33
(request :get "http://subdomain.example.com/"))
34
34
{}
35
35
36
+ And scheme-relative routes:
37
+
38
+ user=> (route-matches "//subdomain.example.com/"
39
+ (request :get "http://subdomain.example.com/"))
40
+ {}
41
+ user=> (route-matches "//subdomain.example.com/"
42
+ (request :get "https://subdomain.example.com/"))
43
+ {}
44
+
36
45
Clout supports both keywords and wildcards. Keywords (like ": title ") will
37
46
match any character but the following: ` / . , ; ? ` . Wildcards (* ) will match
38
47
anything.
Original file line number Diff line number Diff line change 111
111
(recur results src clauses))))))
112
112
113
113
(defn- absolute-url?
114
- " True if the path contains an absolute URL."
114
+ " True if the path contains an absolute or scheme-relative URL."
115
115
[path]
116
- (boolean (re-matches #"https?://.*" path)))
116
+ (boolean (re-matches #"( https?:)? //.*" path)))
117
117
118
118
(defn route-compile
119
119
" Compile a path string using the routes syntax into a uri-matcher struct."
130
130
(apply str
131
131
(lex path
132
132
splat " (.*?)"
133
+ #"^//" " https?://"
133
134
word #(str " (" (word-regex %) " )" )
134
135
literal #(re-escape (.group %)))))
135
136
(remove nil?
Original file line number Diff line number Diff line change 74
74
" http://localhost/"
75
75
{:scheme :http
76
76
:headers {" host" " localhost" }
77
- :uri " /" })))
77
+ :uri " /" }))
78
+ (is (route-matches
79
+ " //localhost/"
80
+ {:scheme :http
81
+ :headers {" host" " localhost" }
82
+ :uri " /" }))
83
+ (is (route-matches
84
+ " //localhost/"
85
+ {:scheme :https
86
+ :headers {" host" " localhost" }
87
+ :uri " /" })))
78
88
79
89
(deftest url-port-paths
80
90
(let [req (request :get " http://localhost:8080/" )]
You can’t perform that action at this time.
0 commit comments