Custom Response Body

EnRoute Technical Reference

EnRoute plugins/filters can be used to provide custom response bodies. EnRoute provides several extension mechanisms like WebAssembly and Lua. Lua script can be attached both at the Route level and Global level to define custom responses.

The following example provides a mechanism to customize responses and response code per-route

apiVersion: enroute.saaras.io/v1
kind: RouteFilter
metadata:
  labels:
    component: lua
    configscope: vhconfig
  name: luafilter
  namespace: httpbin
  resourceVersion: "1224971"
  uid: dce13863-418f-47e5-a354-434a9a739e08
spec:
  name: luafilter
  routeFilterConfig:
    config: |
      function envoy_on_request(request_handle)
       -- nothing to do on request path
      end

      function envoy_on_response(response_handle)
         -- if response is a 500, update it to 404 with a friendly message
         if response_handle:headers():get(":status") == "500" then
           response_handle:body():setBytes("<html><b>This should not have happened!<b></html>")
           response_handle:headers():replace(":status", 404)
         end
      end
  type: route_filter_lua