-
Notifications
You must be signed in to change notification settings - Fork 5k
Description
Title: The lua stream handle API should support statusLine() and startLine() methods
Description:
HTTP requests are formatted as follows:
- a start line
- headers
- body
HTTP responses are formatted as follows:
- a status line
- headers
- body
There is currently no support for accessing the start line of HTTP requests, or the status line of HTTP responses. There are however access methods for the other parts of HTTP messages, namely headers()
, body()
and bodyChunks()
.
When the response is coming from Envoy, the status can be access through a special header:
-- Called on the response path.
function envoy_on_response(response_handle)
response_handle:headers():get(":status")
end
However this is an undocumented way to access the HTTP response status code and likely this can't be relied on as it is an undocumented feature (I would happily be pointed to the documentation, if it happens that I am wrong).
This issue proposes the implementation of startLine()
for requests and statusLine()
for responses, i.e.
-- Called on the request path.
function envoy_on_request(request_handle)
-- retrieves HTTP request method (GET, POST, PUT, HEAD...)
request_handle:startLine():method()
-- retrieves the HTTP request target (example: /background.png, http://developer.mozilla.org/en-US/docs/Web/HTTP/Messages)
request_handle:startLine():target()
-- retrieves the HTTP version (e.g. HTTP/1.1)
request_handle:startLine():version()
end
-- Called on the response path.
function envoy_on_response(response_handle)
-- Retrieves protocol (e.g. HTTP/1.1)
response_handle:statusLine():protocol()
-- Retrieves status code (e.g. 200, 404, 503)
response_handle:statusLine():statusCode()
-- Retrieves status text (e.g. OK, Not Found, Found)
response_handle:statusLine():statusText)
end
[optional Relevant Links:]
HTTP message structure: https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages
Current documentation: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#