Mercurial Hosting > luan
annotate src/goodjava/webserver/handlers/IndexHandler.java @ 1607:fa066aaa068c
nginx caching
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 30 Apr 2021 20:23:28 -0600 |
parents | 27efb1fcbcb5 |
children |
rev | line source |
---|---|
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
1 package goodjava.webserver.handlers; |
1137 | 2 |
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
3 import goodjava.webserver.Handler; |
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
4 import goodjava.webserver.Request; |
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
5 import goodjava.webserver.Response; |
1137 | 6 |
7 | |
8 public final class IndexHandler implements Handler { | |
9 private final Handler handler; | |
10 private final String indexName; | |
11 | |
12 public IndexHandler(Handler handler) { | |
13 this(handler,"index.html"); | |
14 } | |
15 | |
16 public IndexHandler(Handler handler,String indexName) { | |
17 this.handler = handler; | |
18 this.indexName = indexName; | |
19 } | |
20 | |
21 public Response handle(Request request) { | |
22 if( request.path.endsWith("/") ) { | |
23 String path = request.path; | |
24 try { | |
25 request.path += indexName; | |
1167 | 26 return handler.handle(request); |
1137 | 27 } finally { |
28 request.path = path; | |
29 } | |
1167 | 30 } else |
31 return handler.handle(request); | |
1137 | 32 } |
33 } |