Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit d50320d

Browse files
committed
Finished file handler?
1 parent 00262ed commit d50320d

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

src/ktt/lib/httpserver/handler/FileHandler.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,33 @@ public final void handle(final SimpleHttpExchange exchange) throws IOException{
4848
final String rel = exchange.getContext().substring(exchange.getHttpContext().getPath().length());
4949

5050
String match = "";
51-
for(String key : files.keySet())
51+
for(final String key : files.keySet())
5252
if(rel.startsWith(key) && key.startsWith(match))
5353
match = key;
5454

55-
if(match.isEmpty())
56-
for(String key : directories.keySet())
55+
if(!match.isEmpty() && files.containsKey(match)){
56+
final FileEntry entry = files.get(match);
57+
handle(exchange,entry.getFile(),entry.getBytes());
58+
}else{
59+
match = "";
60+
for(final String key : directories.keySet())
5761
if(rel.startsWith(key) && key.startsWith(match))
5862
match = key;
5963

60-
// todo
64+
if(!match.isEmpty() && directories.containsKey(match)){
65+
final DirectoryEntry entry = directories.get(match);
66+
final String rel2;
67+
try{
68+
rel2 = rel.substring(match.length()+1);
69+
70+
final File file;
71+
if((file = entry.getFile(rel2)) != null){
72+
handle(exchange, file, entry.getBytes(rel2)); return;
73+
}
74+
}catch(final IndexOutOfBoundsException ignored){ }
75+
}
76+
handle(exchange,null,null);
77+
}
6178
}
6279

6380
public void handle(final SimpleHttpExchange exchange, final File source, final byte[] bytes) throws IOException {

0 commit comments

Comments
 (0)