std::cgi
A utility module for writing CGI scripts in Pyro.
Requests
-
Request() -> Request -
A utility class for handling CGI requests.
- Automatically parses parameter values from the request's query string.
-
Automatically parses parameter values from the request's body if the
Content-Typeheader isapplication/x-www-form-urlencoded.
The Request class has the following methods:
-
:body() -> str -
Returns the request's body as a string.
-
:found(key) -> bool -
Returns
trueif at least one parameter value forkeywas found, wherekeyis a query-string or form parameter. -
:from_json() -> map|vec|str|i64|f64|bool|null|err -
Attempts to parse the request's body as JSON, returning the result. Returns an
errif the body is not valid JSON. -
:params() -> map[string, vec[str]] -
Returns a map containing parsed parameter values.
-
:value(key) -> str|err -
Returns the parameter value for
keywherekeyis a query-string or form parameter.-
Returns an
errifkeywas not found. -
If multiple values were found for
key, returns the final value to be parsed.
-
Returns an
-
:values(key) -> vec[str] -
Returns the list of parameter values for
keywherekeyis a query-string or form parameter.Returns an empty vector if
keywas not found.
Responses
-
Response() -> Response -
A utility class for handling CGI responses.
The Response class has the following methods:
-
:add_header(header: str) -> Response -
Adds a HTTP header to the response.
Returns
selfto allow chaining. -
:make_301_redirect(url: str) -> Response -
Adds the appropriate headers for a
301(permanent) redirect to the specified URL.Returns
selfto allow chaining. -
:make_302_redirect(url: str) -> Response -
Adds the appropriate headers for a
302redirect to the specified URL.Returns
selfto allow chaining. -
:make_303_redirect(url: str) -> Response -
Adds the appropriate headers for a
303redirect to the specified URL.Returns
selfto allow chaining. -
:make_307_redirect(url: str) -> Response -
Adds the appropriate headers for a
307(temporary) redirect to the specified URL.Returns
selfto allow chaining. -
:send() -
Writes the response to the standard output stream.
-
:write(arg: any) -> Response
:write(format_string: str, *args: any) -> Response -
Writes to the response's
bodybuffer.-
Calling this method with a single argument is equivalent to calling
$str()on that argument first and writing the resulting string. -
Calling this method with more than one argument is equivalent to calling
$fmt()on those arguments first and writing the resulting string.
Returns
selfto allow chaining.You can call this method multiple times to keep appending content to the response.
No data is sent until the
:send()method is called. -
Calling this method with a single argument is equivalent to calling