Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

route/resources throws exception when user enters directory into address bar #43

Closed
craftycheese opened this issue Oct 5, 2011 · 4 comments

Comments

@craftycheese
Copy link

When a user tries to visit /img/ instead of /img/dog.jpg the browser hangs and an exception shows up under lein ring. Shouldn't route/resource return nil in this case and let some other handler take care of this? This would allow the default handler to send back a 404 http reply.

Here is the project.clj file:

(defproject compojure-experiment "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.2.1"]
[compojure "0.6.5"]]
:dev-dependencies [[lein-ring "0.4.5"]]
:ring {:handler compojure-experiment.core/app})

Here is compojure-experiment/core.clj:
(ns compojure-experiment.core
(:use compojure.core)
(:require [compojure.route :as route]
[compojure.handler :as handler]))

(defroutes main-routes
(GET "/" [] "<h1>Fee fi fo fum</h1>")
(route/resources "/img/")
(route/resources "/css/")
(route/not-found "<h1>No such page, fool.</h1>"))

(def app
(handler/site main-routes))

Here is the url:
http://127.0.0.1:3000/img/

Here is the stack trace:

2011-10-05 09:40:01.600:WARN::/img/
java.io.FileNotFoundException: /home/afonso/clojure/resume/tin-can/compojure-experiment/resources/public (Is a directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:137)
at ring.util.servlet$set_body.invoke(servlet.clj:78)
at ring.util.servlet$update_servlet_response.invoke(servlet.clj:108)
at ring.adapter.jetty$proxy_handler$fn__77.invoke(jetty.clj:18)
at ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler$0.handle(Unknown Source)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

@JulianBirch
Copy link

I've just encountered the same problem. In my case, it was caused by me dropping the explicit mapping for "/" from my routes. Rather than then giving me a not-found, which was the next rule, it tries to read the resources directory as a file. Yes, I have

(route/resource "/")
(route/not-found "Page not found")

@weavejester
Copy link
Owner

This is a problem with the ring.util.response/resource-response function in Ring. I'll open an issue for it there and get it fixed.

@weavejester
Copy link
Owner

Should be fixed in master now.

@JulianBirch
Copy link

Thankyou, saw the ring pull go past last week. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants