Skip to content

Matching Expression Language

Paolo Venturi edited this page May 22, 2019 · 17 revisions

Expression Language for Matching Conditions

In Carapace configuration, properties like route and filter features a field match for defining whether to apply what defined. The way you can define whether to apply a route or a filter is by an integrated expression language built just to define matching conditions about incoming request properties like uri, headers, method etc. In this section will be exposed the Matching Expression Language to be used within matchers, a bounch of request properties that can be managed with it toghether with some examples.

Expression Language Syntax

The expression language just allows boolean expression by composing comparing conditions between constant values and the Request properties.

Request Properties

Each property has to be specified as request.PROPERTY_NAME

Operators

Right now, available operators are:

  • Equals operator = "VALUE"
  • Regular Expression operator ~ "VALUE"
  • Boolean operator and
  • Boolean operator or
  • Boolean operator not
  • Parentheses ( )

HTTP Request properties

HTTP URI

request.uri ~ ".*\.css"
request.uri = "/index.html"

HTTP Method

request.method = "POST"
request.method = "GET"
etc

Secure Channel (HTTPS)

secure
not secure

Content Type

request.content-type ~ "text/.*"

HTTP Headers

request.headers.cookie ~ ".*userid.*"
not request.headers.user-agent = "explorer"

Other properties

Listener Address

listener.address = "localhost:8080"

Use Cases:

We want to redirect all non secure (HTTP) GET Requests for path "/index.html" to secure ones. To do so the matching condition we need to use for a Route is:

route.0.match=not secure and request.uri ~ "/index.html" and request.method = "GET"