Easy '304 Not Modified' Responses

ConditionalHeaders feature adds the ability to avoid sending content if the client already has the same content. It does so bychecking the ETag or LastModified properties of the Resource or FinalContent that are sent and comparing these properties to what client indicates it is having. If the conditions allow it, the entire content is not sent and a“304 Not Modified” response is sent instead.

This feature is defined in the class io.ktor.features.ConditionalHeaders and no additional artifacts are required.

Configuration

You can install and use ConditionalHeaders without additional configuration:

  1. install(ConditionalHeaders)

It also allows to configure a lambda to fetch a version list from the generated OutgoingContent passed as parameter of the lambda:

  1. install(ConditionalHeaders) {
  2. version { content -> listOf(EntityTagVersion("tag1")) }
  3. }

Extensibility

Version interface implementations are attached to the Resource instances, and you can return custom implementationswith your own logic. Please note that FinalContent is only checked for ETag and LastModified headers.