forked from undertow-io/undertow
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
core/src/main/java/io/undertow/attribute/ResponseTimeAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.undertow.attribute; | ||
|
||
import io.undertow.server.HttpServerExchange; | ||
|
||
/** | ||
* The response time | ||
*/ | ||
public class ResponseTimeAttribute implements ExchangeAttribute { | ||
|
||
public static final String RESPONSE_TIME_SHORT = "%D"; | ||
public static final String RESPONSE_TIME = "%{RESPONSE_TIME}"; | ||
|
||
public static final ExchangeAttribute INSTANCE = new ResponseTimeAttribute(); | ||
|
||
private ResponseTimeAttribute() {} | ||
|
||
@Override | ||
public String readAttribute(HttpServerExchange exchange) { | ||
return String.valueOf(System.currentTimeMillis() - exchange.getStartTime()); | ||
} | ||
|
||
@Override | ||
public void writeAttribute(HttpServerExchange exchange, String newValue) throws ReadOnlyAttributeException { | ||
throw new ReadOnlyAttributeException("Response Time", newValue); | ||
} | ||
|
||
public static final class Builder implements ExchangeAttributeBuilder { | ||
|
||
@Override | ||
public String name() { | ||
return "Response Time"; | ||
} | ||
|
||
@Override | ||
public ExchangeAttribute build(String token) { | ||
if (token.equals(RESPONSE_TIME) || token.equals(RESPONSE_TIME_SHORT)) { | ||
return ResponseTimeAttribute.INSTANCE; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters