Redirects

The redirect provider allows to inform the client that the location of the actual resource is different than the requested URI.

Kotlin
Host.create()
    .handler(Redirect.to("http://google.com"))
    .run()

In this example, accessing http://localhost:8080 will redirect the client to the Google search engine. Redirect.to(location, temporary) accepts the target as an absolute or relative URI string and a temporary flag (false by default) as its second argument. The status code sent depends on both this flag and the request method: GET/HEAD requests receive a 301 Moved Permanently or, if temporary is set, a 307 Temporary Redirect; other methods receive a 308 Permanent Redirect, which repeats the request with the same method and body at the new location, or, if temporary is set, a 303 See Other, which tells the client to fetch the new location with GET.

Kotlin
val redirect = Redirect.to("https://genhttp.org", temporary = true)