{"action":"created","issue":{"url":"https://api.github.com/repos/perwendel/spark/issues/316","repository_url":"https://api.github.com/repos/perwendel/spark","labels_url":"https://api.github.com/repos/perwendel/spark/issues/316/labels{/name}","comments_url":"https://api.github.com/repos/perwendel/spark/issues/316/comments","events_url":"https://api.github.com/repos/perwendel/spark/issues/316/events","html_url":"https://github.com/perwendel/spark/issues/316","id":98840678,"number":316,"title":"Do not use ResourceHandler to serve static files, use DefaultServlet","user":{"login":"joakime","id":191721,"avatar_url":"https://avatars2.githubusercontent.com/u/191721?v=3","gravatar_id":"","url":"https://api.github.com/users/joakime","html_url":"https://github.com/joakime","followers_url":"https://api.github.com/users/joakime/followers","following_url":"https://api.github.com/users/joakime/following{/other_user}","gists_url":"https://api.github.com/users/joakime/gists{/gist_id}","starred_url":"https://api.github.com/users/joakime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joakime/subscriptions","organizations_url":"https://api.github.com/users/joakime/orgs","repos_url":"https://api.github.com/users/joakime/repos","events_url":"https://api.github.com/users/joakime/events{/privacy}","received_events_url":"https://api.github.com/users/joakime/received_events","type":"User","site_admin":false},"labels":[{"id":290084650,"url":"https://api.github.com/repos/perwendel/spark/labels/Feature%20request","name":"Feature request","color":"c2e0c6","default":false},{"id":290440595,"url":"https://api.github.com/repos/perwendel/spark/labels/Please%20prioritize","name":"Please prioritize","color":"e11d21","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2015-08-03T21:20:45Z","updated_at":"2017-04-11T00:08:35Z","closed_at":null,"body":"See: https://github.com/perwendel/spark/blob/2.2/src/main/java/spark/webserver/SparkServer.java#L238-L242\n\nBack during Jetty 6, this made sense, but the Jetty project has moved on.\n\nThe ResourceHandler is inappropriate for production quality serving of static files, it lacks lots of features that the DefaultServlet is better suited for.\n\nFeatures lacking in ResourceHandler: \n- Resume / Continue\n- Proper mime-type handling (handlers/filters that can modify the response, like gzip filters are going to have a hard time)\n- Partial Requests\n- Response Caching\n- ETag support\n- Built-in *.gz auto-serving of compressed gzip content (no need to use memory/cpu to actually compress the resource) - Eg: request to `/static/main.css` and file `${resourceBase}/static/main.css.gz` exists, serve it instead with compressed content-encoding)\n- Async I/O serving of static resource\n- Welcome Files\n- Direct memory mapped file serving of resources (vastly reduced memory usage)\n\nSee example on stackoverflow for usage of 2 DefaultServlets (the normal one, and an alternate one)\n\nhttp://stackoverflow.com/a/20223103/775715\n"},"comment":{"url":"https://api.github.com/repos/perwendel/spark/issues/comments/293113065","html_url":"https://github.com/perwendel/spark/issues/316#issuecomment-293113065","issue_url":"https://api.github.com/repos/perwendel/spark/issues/316","id":293113065,"user":{"login":"tipsy","id":1521451,"avatar_url":"https://avatars0.githubusercontent.com/u/1521451?v=3","gravatar_id":"","url":"https://api.github.com/users/tipsy","html_url":"https://github.com/tipsy","followers_url":"https://api.github.com/users/tipsy/followers","following_url":"https://api.github.com/users/tipsy/following{/other_user}","gists_url":"https://api.github.com/users/tipsy/gists{/gist_id}","starred_url":"https://api.github.com/users/tipsy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tipsy/subscriptions","organizations_url":"https://api.github.com/users/tipsy/orgs","repos_url":"https://api.github.com/users/tipsy/repos","events_url":"https://api.github.com/users/tipsy/events{/privacy}","received_events_url":"https://api.github.com/users/tipsy/received_events","type":"User","site_admin":false},"created_at":"2017-04-11T00:08:35Z","updated_at":"2017-04-11T00:08:35Z","body":"Let me prefix this with a thanks, and an acknowledgement that you seem to know a lot more about this than I do. I will attempt to answer your questions, but I'm not at all familiar with the current code we have here.\r\n\r\n> `Spark.staticFileLocation(String folder)` and `Spark.externalStaticFileLocation(String location)` are the apparent entry points.\r\n> If `staticFileLocation()` is used, then this should be the static resources served from the `/` context-path. This would be the `ServletContextHandler.setBaseResource()` setting.\r\n> If `externalStaticFileLocation()` is used, then which context-path should this be served under?\r\n\r\nAlso `/`. From a Spark-user-perspective the API shouldn't care if the source is in classpath or external. Does that make sense?\r\nThere is also a wish for supporting multiple calls to `staticFileLocation()` (#734)\r\n\r\n> I think the addition of these static resource locations should be delegated to the `EmbeddedServer` interface.\r\n\r\nThat would mean static files would only work in embedded mode. I asked Per about this before, and he doesn't like the idea. Why do you think it should be like this?\r\n\r\n> There could be other exposed features of the static file serving too.\r\n> **LIST**\r\n> The `staticFileLocation()` method in particular seems like the wrong place (timing of startup wise).\r\n> That is an immutable location associated with the `javax.servlet.ServletContext` and all embedded servlet servers will have the same requirement, to declare the base resource location for the `ServletContext`.\r\nThat location should be defined before you attempt to start/create the `ServletContext` (or `ServletContextHandler`) as a proper location is needed for any library wanting to use the following `ServletContext` methods during the startup lifecycle of the servlet/context/container.\r\n\r\nThe static file location must be set before route-mapping, which initializes the server. This sounds correct according to what you just said (?). \r\n\r\n> All of this makes me wonder if the entire `StaticFiles` and `StaticFilesConfiguration` still make sense?\r\n\r\nIn what way doesn't the API make sense, and what would the alternative be? Spark abstracts away a lot of things, as our main focus is keeping the API clean and understanable. If people have some static resource, they can tell Spark where to find them using `staticFileLocation()`. I personally like the `staticFiles.location()` syntax a lot, I would be sad to see it go.\r\n\r\n`StaticFilesConfiguration`, however, I don't really care for.  It could hopefully all be removed."}}
{"actor":{"display_login":"tipsy"}}