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

Commit 0a02094

Browse files
committed
Update TemporaryHandler.java
1 parent 8f5b0fc commit 0a02094

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/com/kttdevelopment/simplehttpserver/handler/TemporaryHandler.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@ public class TemporaryHandler implements HttpHandler {
99

1010
private final HttpHandler handler;
1111

12+
private boolean hasExpiry;
13+
private long initTime;
14+
private long maxTime;
15+
1216
public TemporaryHandler(final HttpHandler handler){
1317
this.handler = handler;
1418
}
1519

1620
public TemporaryHandler(final HttpHandler handler, final long maxTime){
1721
this.handler = handler;
22+
23+
hasExpiry = true;
24+
initTime = System.currentTimeMillis();
25+
this.maxTime = maxTime;
1826
}
1927

2028
@Override
2129
public final void handle(final HttpExchange exchange) throws IOException{
22-
handler.handle(exchange);
30+
if(!hasExpiry || maxTime + initTime < System.currentTimeMillis())
31+
handler.handle(exchange);
2332
exchange.getHttpContext().getServer().removeContext(exchange.getHttpContext());
2433
}
2534

0 commit comments

Comments
 (0)