Couper Documentation

edge

Modifiers

Request Header

Couper offers three attributes to manipulate the request header fields. The header attributes can be defined unordered within the configuration file but will be executed ordered as follows:

ModifierContextsDescription
remove_request_headersEndpoint Block, Proxy Block, Backend Block, Error HandlerList of request header to be removed from the upstream request.
set_request_headersEndpoint Block, Proxy Block, Backend Block, Error HandlerKey/value(s) pairs to set request header in the upstream request.
add_request_headersEndpoint Block, Proxy Block, Backend Block, Error HandlerKey/value(s) pairs to add request header to the upstream request.

All *_request_headers are executed from: endpoint, proxy, backend and error_handler.

Response Header

Couper offers three attributes to manipulate the response header fields. The header attributes can be defined unordered within the configuration file but will be executed ordered as follows:

ModifierContextsDescription
remove_response_headersServer Block, Files Block, SPA Block, API Block, Endpoint Block, Proxy Block, Backend Block, Error HandlerList of response header to be removed from the client response.
set_response_headersServer Block, Files Block, SPA Block, API Block, Endpoint Block, Proxy Block, Backend Block, Error HandlerKey/value(s) pairs to set response header in the client response.
add_response_headersServer Block, Files Block, SPA Block, API Block, Endpoint Block, Proxy Block, Backend Block, Error HandlerKey/value(s) pairs to add response header to the client response.

All *_response_headers are executed from: server, files, spa, api, endpoint, proxy, backend and error_handler.

Set Response Status

The set_response_status attribute allows to modify the HTTP status code to the given value.

ModifierContextsDescription
set_response_statusEndpoint Block, Backend Block, Error HandlerHTTP status code to be set to the client response.

If the HTTP status code ist set to 204, the response body and the HTTP header field Content-Length is removed from the client response, and a warning is logged.

Parameters

Query Parameter

Couper offers three attributes to manipulate the query parameter. The query attributes can be defined unordered within the configuration file but will be executed ordered as follows:

ModifierContextsDescription
remove_query_paramsEndpoint Block, Proxy Block, Backend Block, Error HandlerList of query parameters to be removed from the upstream request URL.
set_query_paramsEndpoint Block, Proxy Block, Backend Block, Error HandlerKey/value(s) pairs to set query parameters in the upstream request URL.
add_query_paramsEndpoint Block, Proxy Block, Backend Block, Error HandlerKey/value(s) pairs to add query parameters to the upstream request URL.

All *_query_params are executed from: endpoint, proxy, backend and error_handler.

server "my_project" {
  api {
    endpoint "/" {
      proxy {
        backend = "example"
      }
    }
  }
}

definitions {
  backend "example" {
    origin = "http://example.com"

    remove_query_params = ["a", "b"]

    set_query_params = {
      string = "string"
      multi = ["foo", "bar"]
      "${request.headers.example}" = "yes"
    }

    add_query_params = {
      noop = request.headers.noop
      null = null
      empty = ""
    }
  }
}

Form Parameter

Couper offers three attributes to manipulate the form parameter. The form attributes can be defined unordered within the configuration file but will be executed ordered as follows:

ModifierContextsDescription
remove_form_paramsEndpoint Block, Proxy Block, Backend Block, Error HandlerList of form parameters to be removed from the upstream request body.
set_form_paramsEndpoint Block, Proxy Block, Backend Block, Error HandlerKey/value(s) pairs to set form parameters in the upstream request body.
add_form_paramsEndpoint Block, Proxy Block, Backend Block, Error HandlerKey/value(s) pairs to add form parameters to the upstream request body.

All *_form_params are executed from: endpoint, proxy, backend and error_handler.

The *_form_params apply only to requests with the POST method and the Content-Type: application/x-www-form-urlencoded HTTP header field.

server "my_project" {
  api {
    endpoint "/" {
      proxy {
        backend = "example"
      }
    }
  }
}

definitions {
  backend "example" {
    origin = "http://example.com"

    remove_form_params = ["a", "b"]

    set_form_params = {
      string = "string"
      multi = ["foo", "bar"]
      "${request.headers.example}" = "yes"
    }

    add_form_params = {
      noop = request.headers.noop
      null = null
      empty = ""
    }
  }
}