|
20 | 20 | import org.eclipse.jetty.server.Server; |
21 | 21 | import org.eclipse.jetty.server.handler.AbstractHandler; |
22 | 22 | import org.javawebstack.httpserver.handler.*; |
| 23 | +import org.javawebstack.httpserver.util.DirectoryFileProvider; |
| 24 | +import org.javawebstack.httpserver.util.ResourceFileProvider; |
23 | 25 | import org.javawebstack.httpserver.websocket.InternalWebSocketAdapter; |
24 | 26 | import org.javawebstack.httpserver.websocket.InternalWebSocketRequestHandler; |
25 | 27 | import org.javawebstack.injector.Injector; |
@@ -130,13 +132,25 @@ public HTTPServer delete(String pattern, RequestHandler... handlers){ |
130 | 132 | } |
131 | 133 |
|
132 | 134 | public HTTPServer staticDirectory(String pathPrefix, File directory){ |
133 | | - return get(pathPrefix+(pathPrefix.endsWith("/") ? "" : "/")+"{*:path}", new StaticDirectoryHandler(directory)); |
| 135 | + return staticHandler(pathPrefix, new StaticFileHandler().add(new DirectoryFileProvider(directory))); |
134 | 136 | } |
135 | 137 |
|
136 | 138 | public HTTPServer staticDirectory(String pathPrefix, String directory){ |
137 | 139 | return staticDirectory(pathPrefix, new File(directory)); |
138 | 140 | } |
139 | 141 |
|
| 142 | + public HTTPServer staticResourceDirectory(String pathPrefix, String prefix){ |
| 143 | + return staticResourceDirectory(pathPrefix, null, prefix); |
| 144 | + } |
| 145 | + |
| 146 | + public HTTPServer staticResourceDirectory(String pathPrefix, ClassLoader classLoader, String prefix){ |
| 147 | + return staticHandler(pathPrefix, new StaticFileHandler().add(new ResourceFileProvider(classLoader, prefix))); |
| 148 | + } |
| 149 | + |
| 150 | + public HTTPServer staticHandler(String pathPrefix, StaticFileHandler handler) { |
| 151 | + return get(pathPrefix+(pathPrefix.endsWith("/") ? "" : "/")+"{*:path}", handler); |
| 152 | + } |
| 153 | + |
140 | 154 | public HTTPServer beforeDelete(String pattern, RequestHandler... handlers){ |
141 | 155 | return beforeRoute(HttpMethod.DELETE, pattern, handlers); |
142 | 156 | } |
|
0 commit comments