added transformation_gzip

This commit is contained in:
Unbit
2013-04-18 18:05:01 +02:00
parent 546dadbd06
commit 30b4ea7d49
3 changed files with 38 additions and 0 deletions
+2
View File
@@ -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);
+30
View File
@@ -0,0 +1,30 @@
#include <uwsgi.h>
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,
};
@@ -0,0 +1,6 @@
NAME='transformation_gzip'
CFLAGS = []
LDFLAGS = []
LIBS = []
GCC_LIST = ['gzip']