Skip to content

httpSetResponseHeader

Server-side
Caution

This function works only in the HTTP interface, meaning in .html files - it is not available in .lua files.

This function sets the value for the specified HTTP response header of the current HTML page.

Syntax

bool httpSetResponseHeader ( ​string headerName, ​string headerValue )
Required arguments
  • headerName: The HTTP header whose value is being set. You can find a list of header names here. Header names should be all lower case letters.
  • headerValue: The new value for the specified header.

Returns

Returns true if the header value was set successfully, false otherwise.

  • bool: result

Code Examples

server

This example displays an image on the page by setting the header content-type to image/png.

<*
local file = fileOpen("cat.png")
if file then
while not fileIsEOF(file) do
buffer = fileRead(file, 500)
httpWrite(buffer, buffer:len())
end
fileClose(file)
httpSetResponseHeader("content-type", "image/png")
else
*>
Could not read file
<*
end
*>