Mercurial Hosting > luan
comparison src/goodjava/webserver/handlers/IndexHandler.java @ 1402:27efb1fcbcb5
move luan.lib to goodjava
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 17 Sep 2019 01:35:01 -0400 |
parents | src/luan/lib/webserver/handlers/IndexHandler.java@643cf1c37723 |
children |
comparison
equal
deleted
inserted
replaced
1401:ef1620aa99cb | 1402:27efb1fcbcb5 |
---|---|
1 package goodjava.webserver.handlers; | |
2 | |
3 import goodjava.webserver.Handler; | |
4 import goodjava.webserver.Request; | |
5 import goodjava.webserver.Response; | |
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; | |
26 return handler.handle(request); | |
27 } finally { | |
28 request.path = path; | |
29 } | |
30 } else | |
31 return handler.handle(request); | |
32 } | |
33 } |