pomerium/internal/controlplane/luascripts/fix-misdirected.lua
Caleb Doxsey b2ceaa9e91
reduce memory usage by handling http/2 coalescing via a lua script (#1779)
* add support for proxy protocol on HTTP listener (#1777)

* add support for proxy protocol on HTTP listener

* rename option, add doc

* reduce memory usage by handling http/2 coalescing via a lua script

* move script to file

* use wellknown

* fix integration test
2021-01-19 08:45:28 -07:00

23 lines
903 B
Lua

function envoy_on_request(request_handle)
local headers = request_handle:headers()
local dynamic_meta = request_handle:streamInfo():dynamicMetadata()
local authority = headers:get(":authority")
-- store the authority header in the metadata so we can retrieve it in the response
dynamic_meta:set("envoy.filters.http.lua", "request.authority", authority)
end
function envoy_on_response(response_handle)
local headers = response_handle:headers()
local dynamic_meta = response_handle:streamInfo():dynamicMetadata()
local authority =
dynamic_meta:get("envoy.filters.http.lua")["request.authority"]
-- if we got a 404 (no route found) and the authority header doens't match
-- assume we've coalesced http/2 connections and return a 421
if headers:get(":status") == "404" and authority ~= "%s" then
headers:replace(":status", "421")
end
end