Package ratpack.core.handling
Class ResponseTimer
- java.lang.Object
- 
- ratpack.core.handling.ResponseTimer
 
- 
- All Implemented Interfaces:
- Handler
 
 public class ResponseTimer extends Object implements Handler Ahandler, that adds a "X-Response-Time" header to all requests indicating how long it took to start sending a response in milliseconds.It is generally most convenient to add a timer into the handler chain by using the decorator()method, which provides aHandlerDecorator.import ratpack.core.handling.ResponseTimer; import ratpack.test.embed.EmbeddedApp; import ratpack.core.http.client.ReceivedResponse; import static org.junit.jupiter.api.Assertions.*; public class Example { public static void main(String... args) throws Exception { EmbeddedApp.of(s -> s .registryOf(r -> r .add(ResponseTimer.decorator()) ) .handler(r -> ctx -> ctx.render("ok") ) ).test(httpClient -> { ReceivedResponse response = httpClient.get(); assertNotNull(response.getHeaders().get("X-Response-Time")); }); } }See handle(Context)for precise detail on what is timed, and the time value.
- 
- 
Field SummaryFields Modifier and Type Field Description static StringHEADER_NAMEThe name of the header with the time value: "X-Response-Time".
 - 
Constructor SummaryConstructors Constructor Description ResponseTimer()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HandlerDecoratordecorator()Creates a handler decorator that prepends a response timer to the rest of the handlers.voidhandle(Context ctx)Adds the number of milliseconds of elapsed time betweenRequest.getTimestamp()and when the response is ready to be sent.
 
- 
- 
- 
Field Detail- 
HEADER_NAMEpublic static final String HEADER_NAME The name of the header with the time value: "X-Response-Time".- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
decoratorpublic static HandlerDecorator decorator() Creates a handler decorator that prepends a response timer to the rest of the handlers.- Returns:
- a handler decorator.
 
 - 
handlepublic void handle(Context ctx) Adds the number of milliseconds of elapsed time betweenRequest.getTimestamp()and when the response is ready to be sent.The timer is stopped, and the header added, by Response.beforeSend(Action). This means that the time value is the elapsed time, commonly referred to as wall clock time, and not CPU time. Similarly, it does not include the time to actually start sending data out over the socket. It effectively times the application processing.The value is in milliseconds, accurate to 5 decimal places. 
 
- 
 
-