HttpSetResponseHeader: Difference between revisions
Jump to navigation
Jump to search
(New page: __NOTOC__ {{HTTP function}} This function sets the value for the current HTML page's response header. ==Syntax== <syntaxhighlight lang="lua"> bool httpSetResponseHeader ( string headerName, string headerV...) |
(Example) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{HTTP function}} | {{HTTP function}} | ||
This function sets the value for the current HTML page | This function sets the value for the specified HTTP response header of the current HTML page. | ||
==Syntax== | ==Syntax== | ||
Line 9: | Line 9: | ||
==Required Arguments== | ==Required Arguments== | ||
'''headerName:''' the HTTP header whose value is being set. | *'''headerName:''' the HTTP header whose value is being set. You can find a list of header names [http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html here]. Header names should be all ''lower case'' letters. | ||
'''headerValue:''' the new value for the specified header. | *'''headerValue:''' the new value for the specified header. | ||
===Returns=== | ===Returns=== | ||
Line 16: | Line 16: | ||
==Example== | ==Example== | ||
[[ | Using httpSetResponseHeader to set the content type. (Example from [[httpWrite]]) | ||
<syntaxhighlight lang="lua"> | |||
<* | |||
local file = fileOpen ( "icons/icon.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 | |||
*> | |||
</syntaxhighlight> | |||
==See Also== | ==See Also== | ||
{{HTTP functions}} | {{HTTP functions}} |
Latest revision as of 12:30, 28 September 2013
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.
Example
Using httpSetResponseHeader to set the content type. (Example from httpWrite)
<* local file = fileOpen ( "icons/icon.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 *>
See Also
These functions can only be used from within lua blocks in HTML pages hosted by the server
- httpClear
- httpRequestLogin
- httpSetResponseCode
- httpSetResponseCookie
- httpSetResponseHeader
- httpWrite