|
cwist
Modern C web framework with libttak runtime
|
test_client.c interface. More...
#include <cwist/sys/app/test_client.h>#include <cwist/core/mem/alloc.h>#include <cwist/core/sstring/sstring.h>#include <string.h>#include <strings.h>#include <stdlib.h>#include <stdio.h>#include <ctype.h>
Go to the source code of this file.
Functions | |
| cwist_test_client * | cwist_test_client_create (cwist_app *app) |
| Create a test HTTP client bound to an app. | |
| void | cwist_test_client_destroy (cwist_test_client *client) |
| Destroy a test client and free all its cookies. | |
| cwist_http_response * | cwist_test_client_request_ex (cwist_test_client *client, cwist_http_method_t method, const char *path, const cwist_test_client_request_options *opts) |
| Send a request with explicit method and options. | |
| cwist_http_response * | cwist_test_client_get (cwist_test_client *client, const char *path) |
| Send a GET request. | |
| cwist_http_response * | cwist_test_client_post (cwist_test_client *client, const char *path, const char *body) |
| Send a POST request with a plain-text body. | |
| cwist_http_response * | cwist_test_client_post_json (cwist_test_client *client, const char *path, const char *json_body) |
| Send a POST request with a JSON body and application/json content type. | |
| cwist_http_response * | cwist_test_client_put (cwist_test_client *client, const char *path, const char *body) |
| Send a PUT request with a plain-text body. | |
| cwist_http_response * | cwist_test_client_delete (cwist_test_client *client, const char *path) |
| Send a DELETE request. | |
| cwist_http_response * | cwist_test_client_patch (cwist_test_client *client, const char *path, const char *body) |
| Send a PATCH request with a plain-text body. | |
| cwist_http_response * | cwist_test_client_post_multipart (cwist_test_client *client, const char *path, const char *field_name, const char *file_name, const char *content_type, const char *data, size_t data_len) |
| Send a POST request with a single-file multipart/form-data body. Builds the multipart body with a fixed boundary, including Content-Disposition and Content-Type headers for the file part. The body buffer is freed before returning. | |
| void | cwist_test_client_set_cookie (cwist_test_client *client, const char *name, const char *value, const char *path) |
Set or replace a cookie in the client's jar. A cookie with the same name gets its value replaced (and path, if path is given); otherwise a new cookie is prepended to the jar. Strings are copied. | |
| const char * | cwist_test_client_get_cookie (cwist_test_client *client, const char *name) |
| Get the value of a cookie from the client's jar. | |
| void | cwist_test_client_clear_cookies (cwist_test_client *client) |
| Remove and free all cookies in the client's jar. | |
test_client.c interface.
Definition in file test_client.c.
| void cwist_test_client_clear_cookies | ( | cwist_test_client * | client | ) |
Remove and free all cookies in the client's jar.
Clear all cookies in the jar.
| client | Client owning the jar; NULL is a no-op. |
Definition at line 459 of file test_client.c.
References cap, cwist_test_client::cookies, and cwist_test_client_cookie::next.
Referenced by cwist_test_client_destroy().
| cwist_test_client * cwist_test_client_create | ( | cwist_app * | app | ) |
Create a test HTTP client bound to an app.
Create a test client for an app.
| app | App to dispatch requests to; must not be NULL. |
Definition at line 187 of file test_client.c.
References cwist_test_client::app, cap, cwist_test_client::cookies, and cwist_alloc().
| cwist_http_response * cwist_test_client_delete | ( | cwist_test_client * | client, |
| const char * | path | ||
| ) |
Send a DELETE request.
Perform a DELETE request.
| client | Client to send through. |
| path | Request path. |
Definition at line 346 of file test_client.c.
References cap, and CWIST_HTTP_DELETE.
| void cwist_test_client_destroy | ( | cwist_test_client * | client | ) |
Destroy a test client and free all its cookies.
Destroy a test client.
| client | Client to destroy; NULL is a no-op. |
Definition at line 199 of file test_client.c.
References cwist_free(), and cwist_test_client_clear_cookies().
| cwist_http_response * cwist_test_client_get | ( | cwist_test_client * | client, |
| const char * | path | ||
| ) |
Send a GET request.
Perform a GET request.
| client | Client to send through. |
| path | Request path, optionally containing a "?query" suffix. |
Definition at line 297 of file test_client.c.
References cap, and CWIST_HTTP_GET.
| const char * cwist_test_client_get_cookie | ( | cwist_test_client * | client, |
| const char * | name | ||
| ) |
Get the value of a cookie from the client's jar.
Get a cookie value from the jar.
| client | Client owning the jar; NULL yields NULL. |
| name | Cookie name to look up. |
Definition at line 450 of file test_client.c.
References cap, and cwist_test_client::cookies.
| cwist_http_response * cwist_test_client_patch | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | body | ||
| ) |
Send a PATCH request with a plain-text body.
Perform a PATCH request.
| client | Client to send through. |
| path | Request path. |
| body | Null-terminated request body; may be NULL. |
Definition at line 356 of file test_client.c.
References cwist_test_client_request_options::body, and CWIST_HTTP_PATCH.
| cwist_http_response * cwist_test_client_post | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | body | ||
| ) |
Send a POST request with a plain-text body.
Perform a POST request.
| client | Client to send through. |
| path | Request path. |
| body | Null-terminated request body; may be NULL. |
Definition at line 307 of file test_client.c.
References cwist_test_client_request_options::body, and CWIST_HTTP_POST.
| cwist_http_response * cwist_test_client_post_json | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | json_body | ||
| ) |
Send a POST request with a JSON body and application/json content type.
Perform a POST request with JSON content-type.
| client | Client to send through. |
| path | Request path. |
| json_body | Null-terminated JSON body; may be NULL. |
Definition at line 320 of file test_client.c.
References cwist_test_client_request_options::body, cap, cwist_test_client_request_options::content_type, and CWIST_HTTP_POST.
| cwist_http_response * cwist_test_client_post_multipart | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | field_name, | ||
| const char * | file_name, | ||
| const char * | content_type, | ||
| const char * | data, | ||
| size_t | data_len | ||
| ) |
Send a POST request with a single-file multipart/form-data body. Builds the multipart body with a fixed boundary, including Content-Disposition and Content-Type headers for the file part. The body buffer is freed before returning.
Perform a POST request with multipart/form-data body simulating a file upload.
| client | Client to send through. |
| path | Request path. |
| field_name | Form field name for the file part; must not be NULL. |
| file_name | File name for the Content-Disposition header; must not be NULL. |
| content_type | MIME type of the file data; must not be NULL. |
| data | Raw file bytes; must not be NULL. |
| data_len | Length of data in bytes. |
Definition at line 375 of file test_client.c.
References cwist_test_client::app, cwist_test_client_request_options::body, cwist_test_client_request_options::body_len, cap, cwist_test_client_request_options::content_type, cwist_alloc(), cwist_free(), and CWIST_HTTP_POST.
| cwist_http_response * cwist_test_client_put | ( | cwist_test_client * | client, |
| const char * | path, | ||
| const char * | body | ||
| ) |
Send a PUT request with a plain-text body.
Perform a PUT request.
| client | Client to send through. |
| path | Request path. |
| body | Null-terminated request body; may be NULL. |
Definition at line 334 of file test_client.c.
References cwist_test_client_request_options::body, and CWIST_HTTP_PUT.
| cwist_http_response * cwist_test_client_request_ex | ( | cwist_test_client * | client, |
| cwist_http_method_t | method, | ||
| const char * | path, | ||
| const cwist_test_client_request_options * | opts | ||
| ) |
Send a request with explicit method and options.
Perform a request with full control over headers, cookies and query.
| client | Client to send through. |
| method | HTTP method to use. |
| path | Request path, optionally containing a "?query" suffix. |
| opts | Optional request options (body, headers, content type, ad-hoc cookies). |
Definition at line 286 of file test_client.c.
| void cwist_test_client_set_cookie | ( | cwist_test_client * | client, |
| const char * | name, | ||
| const char * | value, | ||
| const char * | path | ||
| ) |
Set or replace a cookie in the client's jar. A cookie with the same name gets its value replaced (and path, if path is given); otherwise a new cookie is prepended to the jar. Strings are copied.
Set a persistent cookie in the client's cookie jar.
| client | Client owning the jar; NULL is a no-op. |
| name | Cookie name; must not be NULL. |
| value | Cookie value; NULL clears the stored value. |
| path | Cookie path; NULL leaves the path unchanged for existing cookies or stores no path for new ones. |
Definition at line 422 of file test_client.c.
References cap, cwist_test_client::cookies, cwist_alloc(), and cwist_free().