1
0
mirror of https://github.com/lxsang/ant-http synced 2024-07-01 12:59:47 +02:00

allow plugin to close the connection at will

This commit is contained in:
lxsang 2018-10-19 12:37:26 +02:00
parent f79ef6232a
commit c06e72a3e8
3 changed files with 34 additions and 23 deletions

View File

@ -385,29 +385,7 @@ void *resolve_request(void *data)
void *finish_request(void *data)
{
if (!data)
return NULL;
LOG("Close request\n");
antd_request_t *rq = (antd_request_t *)data;
// free all other thing
if (rq->request)
{
dictionary tmp = dvalue(rq->request, "COOKIE");
if (tmp)
freedict(tmp);
tmp = dvalue(rq->request, "REQUEST_HEADER");
if (tmp)
freedict(tmp);
tmp = dvalue(rq->request, "REQUEST_DATA");
if (tmp)
freedict(tmp);
dput(rq->request, "REQUEST_HEADER", NULL);
dput(rq->request, "REQUEST_DATA", NULL);
dput(rq->request, "COOKIE", NULL);
freedict(rq->request);
}
antd_close(rq->client);
free(rq);
destroy_request(data);
server_config.connection--;
LOG("Remaining connection %d\n", server_config.connection);
return NULL;

View File

@ -585,4 +585,36 @@ int read_buf(void* sock, char*buf,int size)
}
buf[i] = '\0';
return i;
}
/*
We put it here since we want the plugin is able
to destroy the request if it want to
in this case, the plugin should return an empty
with no data
*/
void destroy_request(void *data)
{
if (!data)
return;
LOG("Close request\n");
antd_request_t *rq = (antd_request_t *)data;
// free all other thing
if (rq->request)
{
dictionary tmp = dvalue(rq->request, "COOKIE");
if (tmp)
freedict(tmp);
tmp = dvalue(rq->request, "REQUEST_HEADER");
if (tmp)
freedict(tmp);
tmp = dvalue(rq->request, "REQUEST_DATA");
if (tmp)
freedict(tmp);
dput(rq->request, "REQUEST_HEADER", NULL);
dput(rq->request, "REQUEST_DATA", NULL);
dput(rq->request, "COOKIE", NULL);
freedict(rq->request);
}
antd_close(rq->client);
free(rq);
}

View File

@ -111,4 +111,5 @@ int read_buf(void* sock,char* buf,int i);
int antd_send( void *source, const void* data, int len);
int antd_recv( void *source, void* data, int len);
int antd_close(void* source);
void destroy_request(void *data);
#endif