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

Static files with space characters aren't routed properly #46

Closed
gberenfield opened this issue Dec 16, 2011 · 4 comments
Closed

Static files with space characters aren't routed properly #46

gberenfield opened this issue Dec 16, 2011 · 4 comments

Comments

@gberenfield
Copy link

I first ran into this in noir which has Issue #36 filed against this.

I suspected an upstream bug so created a new compojure app using the wiki example. I placed a pdf in "resources/public/file.pdf" which is found and parsed correctly but "resources/public/spaced%20file.pdf" (in the url) is not.

2011-12-15 21:15:37.305:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
Started server on port 3000
2011-12-15 21:15:37.306:INFO::jetty-6.1.26
2011-12-15 21:15:37.322:INFO::Started SocketConnector@0.0.0.0:3000
2011-12-15 21:16:05.110:WARN::/2011-11-11%20gas.pdf
java.io.FileNotFoundException: /Users/gberenfield/clojure/web/resources/public/spaced%20file.pdf (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:120)
    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)
@weavejester
Copy link
Owner

It looks like this is actually a bug in the clojure.java.io/as-file function. A fix was implemented a few days ago:

clojure/clojure@1538d80#src/clj/clojure/java/io.clj

I guess we might want to think about putting a workaround for this bug in Ring, as Clojure releases tend to be infrequent.

@gberenfield
Copy link
Author

It seems like ring's ring.util.response/resource-response is being used for files as well as that's where the as-file call is made. There's also a ring.util.response/file-response function which maybe could be used for files (with spaces).

Thanks for the quick response :)

@weavejester
Copy link
Owner

Not quite... If a resource is stored on the filesystem, then resource-response returns a java.io.File object. This means that other Ring middleware has access to important details like the modification time. If the resource is anything else (e.g. contained in a jar), then an java.io.InputStream is returned instead.

The logic in Ring is correct; it's just unfortunate that as-file doesn't work with file paths that contain special characters like spaces. I'll probably have to backport the fix from the clojure-core master branch into ring-core, and release a 1.0.1 version.

@gberenfield
Copy link
Author

Great, I see RC2 uses ring 1.0.1 which has the fix. Closing. Many Thanks,
Greg

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

2 participants