Skip to content

Commit

Permalink
fix(agent): remove ability to list files in resource jars
Browse files Browse the repository at this point in the history
  • Loading branch information
notthetup committed Oct 7, 2024
1 parent 4f888cc commit c664ceb
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions src/main/java/org/arl/fjage/connectors/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,13 @@ public void add(String context, String resource, WebServerOptions options) {
for (URL r : res){
String staticWebResDir = r.toExternalForm();
ContextHandler handler = new ContextHandler(context);
if (options.directoryListed) log.warning("Directory listing is not supported for resources in jars");
ResourceHandler resHandler = new ResourceHandler();
resHandler.setResourceBase(staticWebResDir);
resHandler.setWelcomeFiles(new String[]{ "index.html" });
resHandler.setDirectoriesListed(false);
resHandler.setCacheControl(options.cacheControl);
resHandler.setEtags(true);
if (options.directoryListed) {
DirectoryHandler dirHandler = new DirectoryHandler(staticWebResDir);
dirHandler.setHandler(resHandler);
handler.setHandler(dirHandler);
} else{
handler.setHandler(resHandler);
}
handler.setHandler(resHandler);
staticContexts.put(context, handler);
add(handler);
Expand Down Expand Up @@ -317,21 +311,12 @@ public void add(String context, String resource) {
public void add(String context, File dir, WebServerOptions options) {
try {
ContextHandler handler = new ContextHandler(context);
ResourceHandler resHandler = new ResourceHandler();
ResourceHandler resHandler = options.directoryListed ? new DirectoryHandler() : new ResourceHandler();
resHandler.setResourceBase(dir.getCanonicalPath());
resHandler.setWelcomeFiles(new String[]{ "index.html" });
resHandler.setDirectoriesListed(false);
resHandler.setCacheControl(options.cacheControl);
resHandler.setEtags(true);
handler.setHandler(resHandler);
if (options.directoryListed) {
DirectoryHandler dirHandler = new DirectoryHandler(dir.getCanonicalPath());
dirHandler.setHandler(resHandler);
handler.setHandler(dirHandler);
} else{
handler.setHandler(resHandler);
}
staticContexts.put(context, handler);
add(handler);
}catch (IOException ex){
log.warning("Unable to find the directory : " + dir.toString());
Expand Down Expand Up @@ -496,19 +481,15 @@ public WebServerOptions directoryListed(boolean directoryListed) {
*/
private static class DirectoryHandler extends ResourceHandler {

private DirectoryHandler(String resourceBase) {
super();
setResourceBase(resourceBase);
}

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (baseRequest.isHandled()) return;
if (target.endsWith("/")) {
File base = getBaseResource().getFile();
if (base != null && target.endsWith("/")) {
if (request.getContentType() != null && request.getContentType().equals("text/plain")) {
String path = request.getPathInfo();
if (path == null) path = "/";
File dir = new File(getBaseResource().getFile(), path);
File dir = new File(base, path);
if (dir.isDirectory()) {
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
Expand Down

0 comments on commit c664ceb

Please sign in to comment.