Home Contents | # cgi:header | Httpd/CGI | Core4 Lua Event System

## SYNOPSIS

1. cgi:header(header, value)
2. cgi:contentheader(type, subtype)
3. cgi:htmlheader()

## DESCRIPTION

Functions that send HTTP headers back to the requesting client. The functions are only useful when processing the full request from a Lua script (.lua). For all other file types the header is sent automatically.

The header functions can only be called while the request is still in the header phase. Once sending of the actual response content has been started, attempting to send any more headers will make the client mistake the header as content. The header phase ends once cgi:write() has been called at least once.

The first form cgi:header() sends exactly one header line in the form:

Header: Value
Both items are passed in the variables header and value.

The second form sends a full header for the content type as specified in type and subtype.

For example, the call cgi:contentheader("text", "plain") will send:

HTTP/1.0 200 OK Date: (current date and time) Server: Core4Web Content-Type: text/plain Connection: close

The form cgi:htmlheader() is a shortcut for cgi:contentheader("text", "html").

When it is desired to send extra headers, it is best to start with a call to cgi:htmlheader() or cgi:contentheader() and then topping it up with one or more calls to cgi:header().

Note that the function cgi:cookie() also sends a header line.

## SEE ALSO

cgi:cookie(), cgi:write(), cgi:error(), cgi:mkurlpath()