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:

    1. // ...
    2. fun Application.module() {
    3. 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:

    1. install(DefaultHeaders) {
    2. }

    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:

    1. get("/order") {
    2. }