weavejester / clout Goto Github PK
View Code? Open in Web Editor NEWHTTP route-matching library for Clojure
License: Eclipse Public License 1.0
HTTP route-matching library for Clojure
License: Eclipse Public License 1.0
I'd like to be able to match paths like /a:b/12345
(where 12345
is the variable component) with clout, perhaps using a pattern like /a%3Ab/:id
.
(Corollary: I'd like for the path /%61/%61
to be matched by the pattern /a/:x
. That is, matching across sometimes-overzealous percent-encoding.)
Hi there, I'm trying to create a route which has a regex with a negative lookahead, but I can't seem to get it to match any routes at all.
Basically I want to match all possible "/foo/:fragment" routes that do not contain "admin" in the fragment part. I defined a route like so:
(def user-route
(clout/route-compile "/foo/:fragment" {:fragment #"^((?!admin).)*$"}))
However both the tests below return nil:
(clout/route-matches
user-route
(mock/request :get "/foo/user"))
=> nil
(clout/route-matches
user-route
(mock/request :get "/foo/admin"))
=> nil
I've tested this with simpler negative lookahead regexes and had the same result. I'd appreciate any help with this.
See here: Engelberg/instaparse@14c29fb
and the discussion thread here, starting with Sean Corfield's pointing out that Instaparse had an incompatibility with Clojure 1.7.0-alpha6: https://groups.google.com/d/msg/clojure/D2E4HG1yXBc/j_LTy0mHYQEJ
This is a reopen of: #27
Here are my dependencies:
{org.clojure/clojure {:mvn/version "1.10.3"}
org.clojure/tools.cli {:mvn/version "1.0.206"}
http-kit/http-kit {:mvn/version "2.5.3"}
compojure/compojure {:mvn/version "1.6.2"}
}
I’m trying to make a separate build (as a NixOS derivation) where I kind of manually compile a couple of modules like this (without even using anything like deps.edn
). I found an example here: https://stackoverflow.com/questions/29011295/compile-clojure-source-into-class-aot-from-command-line-not-using-lein#29012274
java -cp ${esc backend-classpaths}:"$src"/src \
-Dclojure.compile.path=build \
clojure.lang.Compile \
"$module"
Where ${esc backend-classpaths}
is a list of JAR files of the dependencies described above and "$src"/src
is where my source code is. Then I run it like this:
java -cp ${esc backend-classpaths}:${backendBuiltClasses} clojure_todo_app.main
Where ${backendBuiltClasses}
is a directory with those pre-built classes.
The application successfully starts, arguments get parsed, but when I do a test curl
request I get this error:
java.lang.IllegalArgumentException: No implementation of method: :route-matches of protocol: #'clout.core/Route found for class: clout.core.CompiledRoute
Any ideas what’s wrong?
I also found https://stackoverflow.com/questions/31129470/java-lang-illegalargumentexception-no-implementation-of-method-route-matches but in my case this isn’t useful.
(defmethod route-matches [::compiled-route Map]
[route request]
(route-matches route (if (:absolute? route)
(request-url request)
(:uri request))))
This method matches on (:uri request), which works fine when using a single servlet that is mapped to /, but with multiple servlets at different urls, it would be better to match from the root of the servlet. Replacing (:uri request) with (.getPathInfo (:servlet-request request)) should be enough:
(defmethod route-matches [::compiled-route Map]
[route request]
(route-matches route (if (:absolute? route)
(request-url request)
(.getPathInfo (:servlet-request request)))))
It looks like https://github.com/weavejester/clout/blob/master/src/clout/core.clj#L91 incorrectly excludes ,
from the characters it's willing to match in a path, given the characters allowed in a path (see http://stackoverflow.com/questions/4669692/valid-characters-for-directory-part-of-a-url-for-short-links/4669755#4669755 for one listing of such).
How about supporting Clojure 1.3?
Something like (clout/route-compile "/api/verify?token=abc")
does not work. Is there a recipe, example and unit test for that?
I get the following error when setting :aot :all
and starting the application with lein trampoline run
:
java.lang.IllegalArgumentException: No implementation of method: :route-matches of protocol: #'clout.core/Route found for class: clout.core.CompiledRoute
at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:554)
at clout.core$fn__3514$G__3509__3521.invoke(core.clj:39)
at compojure.core$if_route$fn__3677.invoke(core.clj:40)
I can reproduce this problem if and only if the two conditions mentioned above are in place. So it is not hard to find a workaround but a fix would be appreciated (I did cost me about 2 hours to figure it out).
There seem to be other ways to get the same problem and it might help to see the underlying problem:
If a regex uses capturing groups, path parameters following the pattern get assigned values from the captured group, not the value from the path.
;; Clout version 2.1.2
(clout/route-matches (clout/route-compile "/:foo/:bar" {:foo #"a(bcd|ef)g"})
(mock/request :get "/abcdg/1"))
=> {:bar "bcd", :foo "abcdg"}
expected:
=> {:bar "1", :foo "abcdg"}
After some time in production, a web service using clout started throwing errors of the form:
2013-09-26 18:00:55.934:WARN:oejs.ServletHandler:qtp1525259451-38221: Error for /route/omitted/12345
java.lang.NoClassDefFoundError: clout/core$re_groups_STAR_$iter_242246$fn247$fn_248
at clout.core$re_groups_STAR_$iter_242246$fn_247.invoke(core.clj:23)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:60)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$map$fn__4207.invoke(core.clj:2479)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:60)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$map$fn__4211.invoke(core.clj:2490)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:60)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core.protocols$seq_reduce.invoke(protocols.clj:30)
at clojure.core.protocols$fn__6026.invoke(protocols.clj:54)
at clojure.core.protocols$fn_5979$G5974_5992.invoke(protocols.clj:13)
at clojure.core$reduce.invoke(core.clj:6177)
at clout.core$assoc_keys_with_groups.invoke(core.clj:54)
at clout.core.CompiledRoute.route_matches(core.clj:84)
at compojure.core$if_route$fn__515.invoke(core.clj:38)
at compojure.core$if_method$fn__508.invoke(core.clj:24)
Prod eng sent me this as well by email:
The health checks also seem to be not working predictably. When Nagios and LVS make health check requests it is returning 200 but when I make a call from the browser I get 500 as seen below:
$ tail -f access.20130927.log jvm-default.log
==> access.20130927.log <==
10.3.157.253 - - [27/Sep/2013:01:27:34 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.254 - - [27/Sep/2013:01:27:35 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.253 - - [27/Sep/2013:01:27:46 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.254 - - [27/Sep/2013:01:27:47 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.253 - - [27/Sep/2013:01:27:58 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.254 - - [27/Sep/2013:01:27:59 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.253 - - [27/Sep/2013:01:28:10 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.254 - - [27/Sep/2013:01:28:11 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.253 - - [27/Sep/2013:01:28:22 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.254 - - [27/Sep/2013:01:28:23 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
==> jvm-default.log <==
[GC 1222344K(2027264K), 0.3139680 secs]
[GC 1222670K(2027264K), 0.2166150 secs]
[GC 1222670K(2027264K), 0.2900790 secs]
[GC 1222670K(2027264K), 0.3108980 secs]
[GC 1222670K(2027264K), 0.1812040 secs]
[GC 1222670K(2027264K), 0.2490730 secs]
[GC 1222670K(2027264K), 0.1809940 secs]
[GC 1223499K(2027264K), 0.2554620 secs]
[GC 1223499K(2027264K), 0.2609510 secs]
[GC 1223499K(2027264K), 0.2105590 secs]
[GC 1223499K(2027264K), 0.2915280 secs]
[GC 1223499K(2027264K), 0.4804340 secs]
[GC 1223499K(2027264K), 0.2758370 secs]
==> access.20130927.log <==
10.3.157.253 - - [27/Sep/2013:01:28:34 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.254 - - [27/Sep/2013:01:28:35 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
==> jvm-default.log <==
[GC 1223524K(2027264K), 0.3079560 secs]
[GC 1223524K(2027264K), 0.3189180 secs]
2013-09-26 18:28:42.921:WARN:oejs.ServletHandler:qtp523298718-38244: Error for /vinws/internal/health
java.lang.NoClassDefFoundError: ring/middleware/cookies$parse_cookie_header$iter__937__941
at ring.middleware.cookies$parse_cookie_header.invoke(cookies.clj:42)
at ring.middleware.cookies$parse_cookies.invoke(cookies.clj:85)
at ring.middleware.cookies$wrap_cookies$fn__1029.invoke(cookies.clj:159)
at vinws.servlet$_service$fn__458.invoke(servlet.clj:1)
at ring.util.servlet$make_service_method$fn__50.invoke(servlet.clj:126)
at vinws.servlet$_service.invoke(servlet.clj:1)
at vinws.servlet.service(Unknown Source)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:258)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:445)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:722)
==> access.20130927.log <==
10.4.50.92 - - [27/Sep/2013:01:28:42 +0000] "GET /vinws/internal/health HTTP/1.1" 500 2477 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36"
10.3.157.253 - - [27/Sep/2013:01:28:46 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
10.3.157.254 - - [27/Sep/2013:01:28:47 +0000] "GET /vinws/internal/health HTTP/1.0" 200 - "-" "KeepAliveClient"
This implies that the app is caching responses for existing connections which is very bad.
The server was cycled and the routes worked fine. How could the no class def error be thrown? Is there a reason a long running web service without cycling could go down?
It supports neither Rails ':controller(/:action(/:id))' nor Sinatra '/posts.?:format?' The README is lying ! The README is lying !
I'm writing a HTTP proxy where I use a route match from clout as part of the proxy. The request contains a path with some URL encoded data. Clout decodes this, causing my proxy to deliver invalid URLs (the unencoded versions).
Example: My route matches "/proxy_". I do a request to /proxy/foo%20bar. In my code, I do the proxy with (perform-http-request ... (get-in req [:route-params :_]))
. The value of the route param is"foo bar"
, not what's actually in the URL,"foo%20"bar
. And "foo bar" is not a valid URL value, causing problems down the road when I do the proxying.
Why is the URL modified in the first place? Would it make sense to provide the unescaped values?
According to http://tools.ietf.org/html/rfc3986, + sign should be one of the sub-delims thus it should be a valid character on uri path:
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
Is is possible to upgrade to "instaparse 1.4.2"?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.