wisp/simulate
Values
pub fn bit_array_body(
request: request.Request(wisp.Connection),
data: BitArray,
) -> request.Request(wisp.Connection)
Add a binary body to the request.
The content-type
header is set to application/octet-stream
. You may
want to override/ this with request.set_header
.
pub fn browser_request(
method: http.Method,
path: String,
) -> request.Request(wisp.Connection)
Create a test request with browser-set headers that can be used to test your request handler functions.
The origin
header is set when using this function.
pub fn cookie(
request: request.Request(wisp.Connection),
name: String,
value: String,
security: wisp.Security,
) -> request.Request(wisp.Connection)
Set a cookie on the request.
pub const default_browser_headers: List(#(String, String))
The default headers for browser requests.
pub const default_headers: List(#(String, String))
The default headers for non-browser requests.
pub const default_secret_key_base: String
The default secret key base used for test requests. This should never be used outside of tests.
pub fn form_body(
request: request.Request(wisp.Connection),
data: List(#(String, String)),
) -> request.Request(wisp.Connection)
Add a form data body to the request.
The content-type
header is set to application/x-www-form-urlencoded
.
pub fn header(
request: request.Request(wisp.Connection),
name: String,
value: String,
) -> request.Request(wisp.Connection)
Set a header on a request.
pub fn html_body(
request: request.Request(wisp.Connection),
html: String,
) -> request.Request(wisp.Connection)
Add HTML body to the request.
The content-type
header is set to text/html; charset=utf-8
.
pub fn json_body(
request: request.Request(wisp.Connection),
data: json.Json,
) -> request.Request(wisp.Connection)
Add a JSON body to the request.
The content-type
header is set to application/json
.
pub fn read_body(
response: response.Response(wisp.Body),
) -> String
Read a text body from a response.
Panics
This function will panic if the response body is a file and the file cannot be read, or if it does not contain valid UTF-8.
pub fn read_body_bits(
response: response.Response(wisp.Body),
) -> BitArray
Read a binary data body from a response.
Panics
This function will panic if the response body is a file and the file cannot be read.
pub fn request(
method: http.Method,
path: String,
) -> request.Request(wisp.Connection)
Create a test request that can be used to test your request handler functions.
If you are testing handlers that are intended to be accessed from a browser
(such as those that use cookies) consider using browser_request
instead.
pub fn session(
next_request: request.Request(wisp.Connection),
previous_request: request.Request(wisp.Connection),
previous_response: response.Response(wisp.Body),
) -> request.Request(wisp.Connection)
Continue a browser session from a previous request and response, adopting the request cookies, and updating the cookies as specified by the response.
pub fn string_body(
request: request.Request(wisp.Connection),
text: String,
) -> request.Request(wisp.Connection)
Add a text body to the request.
The content-type
header is set to text/plain
. You may want to override
this with request.set_header
.