Specifies the body of a Lua function that inspects every outgoing HTTP response and overwrites individual fields before being sent to the client.
Returns nil
when nothing is to be changed, or HTTPResponse(t)
where t
is a table with any of the following optional fields:
Code
integer
200
, 404
Text
string
'OK'
, 'Not found'
MajorVersion
x
in HTTP/x.1
in the
response being sent.integer
1
MinorVersion
x
in HTTP/1.x
in the
response being sent.integer
1
Protocol
string
'HTTP'
, 'HTTPS'
Body
string
or nil
'{"foo": "bar"}'
Headers
table
(indexed by number) representing an array of
response headers as {[1]='Name',[2]='Value'}
pairs that are added to
the response being sent, or overwriting existing request headers with
colliding names.
To remove a header from the response, specify nil
as value, i.e.
Headers={..., {[1]='foo',[2]=nil} ...}
.
Duplicate names are supported. A multi-value header such as Foo: bar1,bar2
is defined by specifying Headers={..., {[1]='foo',[2]='bar1'}, {[1]='foo',[2]='bar2'}, ...}
.OutgoingRequest
: See Sending HTTP requests from translation functions for more information.Example of a response_translation_function
body that sets the Location
header to a hardcoded value:
-- Statements go here
print('Setting hardcoded Location')
return HTTPResponse({
Headers = {
{'Location', 'cdn1.com/content.mpd?a=b'}
}
})
The following (iterable) arguments will be known by the function:
Headers
Type: nested table
(indexed by number).
Description: Array of response headers as {[1]='Name',[2]='Value'}
pairs
that are present in the response being sent. Format identical to the
HTTPResponse.Headers
-field specified for the return value above.
A multi-value header such as Foo: bar1,bar2
is seen in
response_translation_function
as Headers={..., {[1]='foo',[2]='bar1'}, {[1]='foo',[2]='bar1'}, ...}
.
Example usage:
for _, header in pairs(Headers) do
print(header[1]..'='..header[2])
end
In addition to the arguments above, the following Lua tables, documented in Global Lua Tables, provide additional data that is available when executing the response translation function: