Response¶
-
class
Response
¶ An HTTP Response
-
headers
: Headers¶ The HTTP headers for this response
-
body
: str¶ the contents of the response body
-
status
: number¶ The HTTP status 3 digit number
-
http_version
: str¶
-
_source
: function¶ (pat:string|nil):string ltn12 source
-
_parsed_headers
: boolean¶
-
_received_body
: boolean¶
-
static
source
(source)¶ Create a request parser from an ltn12 source function
- Parameters
source (fun():str) –
- Return type
- Returns
if return 1 is nil the error string
- Return type
str
-
get_headers
()¶
-
get_content_length
()¶ Attempt to get the value from Content-Length header
- Returns
when not nil the Content-Length
- Return type
number or nil
- Returns
when not nil the error message
- Return type
str or nil
-
next_line
()¶ Get the next line from an incoming request, checking first
if we have reached the end of the content
- Return type
str or nil
- Return type
str or nil
-
get_body
()¶
-
add_header
(key, value)¶ - Parameters
key (any) –
value (any) –
-
set_content_type
(s)¶ Set the Content-Type of the outbound request
- Parameters
s (str) – the mime type for this request
- Return type
-
set_content_length
(len)¶ Set the Content-Length header of the outbound response
- Parameters
len (number) – The length of the content that will be sent
- Return type
-
serialize
()¶ Serialize this full response into a string
- Return type
str
-
append_body
(s)¶ Append text to the body
- Parameters
s (str) – the text to append
- Return type
-
set_status
(n)¶ Set the status for this outgoing request
- Parameters
n (number) – the 3 digit status
- Return type
-
as_source
()¶ Creates an LTN12 source for this request
- Return type
function
-