completed chunked transformation

This commit is contained in:
Unbit
2013-05-01 10:21:35 +02:00
parent e1c5e9e874
commit 8321adf0bc
3 changed files with 15 additions and 2 deletions
+4
View File
@@ -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 -2
View File
@@ -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;
}
+1
View File
@@ -1198,6 +1198,7 @@ struct uwsgi_transformation {
int (*func)(struct wsgi_request *, struct uwsgi_transformation *);
struct uwsgi_buffer *chunk;
uint8_t can_stream;
uint8_t is_final;
void *data;
struct uwsgi_transformation *next;
};