diff --git a/core/utils.c b/core/utils.c index 3de0f990..3df1c0f4 100644 --- a/core/utils.c +++ b/core/utils.c @@ -589,6 +589,8 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) { // send the body only if transformations are successfull struct uwsgi_buffer *ub = wsgi_req->response_buffer; if (uwsgi_apply_transformations(wsgi_req) == 0) { + // teh response_buffer could be changed + ub = wsgi_req->response_buffer; // force true write wsgi_req->response_buffer = NULL; uwsgi_response_write_body_do(wsgi_req, ub->buf, ub->pos); diff --git a/plugins/transformation_gzip/gzip.c b/plugins/transformation_gzip/gzip.c new file mode 100644 index 00000000..837479d6 --- /dev/null +++ b/plugins/transformation_gzip/gzip.c @@ -0,0 +1,30 @@ +#include + +static int transform_gzip(struct wsgi_request *wsgi_req, struct uwsgi_buffer *ub, struct uwsgi_buffer **new) { + struct uwsgi_buffer *gzipped = uwsgi_gzip(ub->buf, ub->pos); + if (!gzipped) { + return -1; + } + // use this new buffer + *new = gzipped; + return 0; +} + +static int uwsgi_routing_func_gzip(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) { + uwsgi_add_transformation(wsgi_req, transform_gzip); + return UWSGI_ROUTE_NEXT; +} + +static int uwsgi_router_gzip(struct uwsgi_route *ur, char *args) { + ur->func = uwsgi_routing_func_gzip; + return 0; +} + +static void router_gzip_register(void) { + uwsgi_register_router("gzip", uwsgi_router_gzip); +} + +struct uwsgi_plugin transformation_gzip_plugin = { + .name = "transformation_gzip", + .on_load = router_gzip_register, +}; diff --git a/plugins/transformation_gzip/uwsgiplugin.py b/plugins/transformation_gzip/uwsgiplugin.py new file mode 100644 index 00000000..76a4bc91 --- /dev/null +++ b/plugins/transformation_gzip/uwsgiplugin.py @@ -0,0 +1,6 @@ +NAME='transformation_gzip' + +CFLAGS = [] +LDFLAGS = [] +LIBS = [] +GCC_LIST = ['gzip']