mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 05:31:44 +00:00
completed chunked transformation
This commit is contained in:
@@ -27,6 +27,8 @@ int uwsgi_apply_transformations(struct wsgi_request *wsgi_req, char *buf, size_t
|
||||
if (!ut->chunk) {
|
||||
ut->chunk = uwsgi_buffer_new(t_len);
|
||||
}
|
||||
// skip final transformations before appending data
|
||||
if (ut->is_final) goto next;
|
||||
if (uwsgi_buffer_append(ut->chunk, t_buf, t_len)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -42,6 +44,7 @@ int uwsgi_apply_transformations(struct wsgi_request *wsgi_req, char *buf, size_t
|
||||
t_len = ut->chunk->pos;
|
||||
// we reset the buffer, so we do not waste memory
|
||||
ut->chunk->pos = 0;
|
||||
next:
|
||||
ut = ut->next;
|
||||
}
|
||||
|
||||
@@ -117,6 +120,7 @@ struct uwsgi_transformation *uwsgi_add_transformation(struct wsgi_request *wsgi_
|
||||
|
||||
ut = uwsgi_malloc(sizeof(struct uwsgi_transformation));
|
||||
ut->func = func;
|
||||
ut->is_final = 0;
|
||||
ut->next = NULL;
|
||||
ut->chunk = NULL;
|
||||
ut->can_stream = 0;
|
||||
|
||||
@@ -10,17 +10,25 @@
|
||||
|
||||
static int transform_chunked(struct wsgi_request *wsgi_req, struct uwsgi_transformation *ut) {
|
||||
struct uwsgi_buffer *ub = ut->chunk;
|
||||
if (uwsgi_buffer_insert_chunked(ub, 0, ub->pos)) return -1;
|
||||
if (uwsgi_buffer_append(ub, "\r\n", 2)) return -1;
|
||||
if (!wsgi_req->headers_sent) {
|
||||
if (uwsgi_response_add_header(wsgi_req, "Transfer-Encoding", 17, "chunked", 7)) return -1;
|
||||
}
|
||||
if (ut->is_final) {
|
||||
if (uwsgi_buffer_insert_chunked(ub, 0, 0)) return -1;
|
||||
}
|
||||
else {
|
||||
if (uwsgi_buffer_insert_chunked(ub, 0, ub->pos)) return -1;
|
||||
}
|
||||
if (uwsgi_buffer_append(ub, "\r\n", 2)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_routing_func_chunked(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) {
|
||||
struct uwsgi_transformation *ut = uwsgi_add_transformation(wsgi_req, transform_chunked, NULL);
|
||||
ut->can_stream = 1;
|
||||
// add a "final" transformation to add the trailing chunk
|
||||
ut = uwsgi_add_transformation(wsgi_req, transform_chunked, NULL);
|
||||
ut->is_final = 1;
|
||||
return UWSGI_ROUTE_NEXT;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user