Default Headers
To install the DefaultHeaders
feature, pass it to the install
function in the application initialization code. This can be the main
function …
… or a specified module:
// ...
fun Application.module() {
install(DefaultHeaders)
To customize a list of default headers, pass a desired header to install
by using the header(name, value)
function. The name
parameter accepts an HttpHeaders
value, for example:
To add a custom header, pass its name as a string value:
install(DefaultHeaders) {
}
Note that the Date
header is cached due to performance reasons and cannot be overridden by using DefaultHeaders
. If you need to override it, do not install the DefaultHeaders
feature and use instead.
If you need to add headers for a specific route only, you can append desired headers into a response. The code snippet below shows how to do this for the /order
request:
get("/order") {
}