mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 12:39:01 -04:00
Let http_state_create() take an "onfree" callback.
This function is called when an HTTP request is being free'd, allowing you to perform any sort of state cleanup attached to the HTTP request.
This commit is contained in:
parent
9ac77d0c9a
commit
d0a6958747
@ -44,7 +44,7 @@ state_setup(struct http_request *req)
|
||||
{
|
||||
struct kore_curl *client;
|
||||
|
||||
client = http_state_create(req, sizeof(*client));
|
||||
client = http_state_create(req, sizeof(*client), NULL);
|
||||
|
||||
if (!kore_curl_init(client,
|
||||
"http://ftp.eu.openbsd.org/pub/OpenBSD/README")) {
|
||||
|
@ -59,7 +59,7 @@ state_setup(struct http_request *req)
|
||||
{
|
||||
struct kore_curl *client;
|
||||
|
||||
client = http_state_create(req, sizeof(*client));
|
||||
client = http_state_create(req, sizeof(*client), NULL);
|
||||
|
||||
/* Initialize curl. */
|
||||
if (!kore_curl_init(client, "https://kore.io")) {
|
||||
|
@ -85,7 +85,7 @@ request_perform_init(struct http_request *req)
|
||||
|
||||
/* Setup our state context (if not yet set). */
|
||||
if (!http_state_exists(req)) {
|
||||
state = http_state_create(req, sizeof(*state));
|
||||
state = http_state_create(req, sizeof(*state), NULL);
|
||||
|
||||
/*
|
||||
* Initialize the kore_pgsql data structure and bind it
|
||||
|
@ -249,6 +249,8 @@ struct http_request {
|
||||
size_t state_len;
|
||||
char *query_string;
|
||||
struct kore_module_handle *hdlr;
|
||||
void (*onfree)(struct http_request *);
|
||||
|
||||
#if defined(KORE_USE_PYTHON)
|
||||
void *py_coro;
|
||||
#endif
|
||||
@ -346,7 +348,8 @@ const char *http_media_type(const char *);
|
||||
void *http_state_get(struct http_request *);
|
||||
int http_state_exists(struct http_request *);
|
||||
void http_state_cleanup(struct http_request *);
|
||||
void *http_state_create(struct http_request *, size_t);
|
||||
void *http_state_create(struct http_request *, size_t,
|
||||
void (*onfree)(struct http_request *));
|
||||
|
||||
int http_argument_urldecode(char *);
|
||||
int http_header_recv(struct netbuf *);
|
||||
|
@ -406,6 +406,9 @@ http_request_free(struct http_request *req)
|
||||
struct http_header *hdr, *next;
|
||||
struct http_cookie *ck, *cknext;
|
||||
|
||||
if (req->onfree != NULL)
|
||||
req->onfree(req);
|
||||
|
||||
#if defined(KORE_USE_TASKS)
|
||||
pending_tasks = 0;
|
||||
for (t = LIST_FIRST(&(req->tasks)); t != NULL; t = nt) {
|
||||
@ -1379,12 +1382,14 @@ http_state_exists(struct http_request *req)
|
||||
}
|
||||
|
||||
void *
|
||||
http_state_create(struct http_request *req, size_t len)
|
||||
http_state_create(struct http_request *req, size_t len,
|
||||
void (*onfree)(struct http_request *))
|
||||
{
|
||||
if (req->hdlr_extra != NULL)
|
||||
fatal("http_state_create: state already exists");
|
||||
|
||||
req->state_len = len;
|
||||
req->onfree = onfree;
|
||||
req->hdlr_extra = kore_calloc(1, len);
|
||||
|
||||
return (req->hdlr_extra);
|
||||
@ -1530,6 +1535,7 @@ http_request_new(struct connection *c, const char *host,
|
||||
req->method = m;
|
||||
req->hdlr = hdlr;
|
||||
req->agent = NULL;
|
||||
req->onfree = NULL;
|
||||
req->referer = NULL;
|
||||
req->flags = flags;
|
||||
req->fsm_state = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user