Koha::Middleware::SetEnv - Plack middleware to allow SetEnv through proxied headers


  builder {
      enable "Koha::Middleware::SetEnv";


This module adds a Plack middleware to convert X-Koha-SetEnv request headers to actual environment variables.

This is needed because Plackified Koha is currently connected to Apache via an HTTP proxy, and SetEnvs are not passed through. Koha uses SetEnvs to pass memcached settings and per-virtualhost styles, search limits and syspref overrides.


Due to how HTTP headers are combined, if you want to set a value with an embedded comma, it must be escaped:

  SetEnv OVERRIDE_SYSPREF_LibraryName "The Best, Truly the Best, Koha Library"
  RequestHeader add X-Koha-SetEnv "OVERRIDE_SYSPREF_LibraryName The Best\, Truly the Best\, Koha Library"


This system was designed to use a single header for reasons of security. We have no way of knowing whether a given request header was set by Apache or the original client, so we have to clear any relevant headers before Apache starts adding them. This is only really practical for a single header name.


Jesse Weaver, <jweaver@bywatersolutions.com>