From c723d492d024eedac846866713d697356097b3cc Mon Sep 17 00:00:00 2001 From: wbaumann Date: Tue, 11 Mar 2014 21:53:13 +0000 Subject: [PATCH] Support compression for GET responses --- ChangeLog | 7 ++++++- src/defaults.h | 3 +++ src/mount_davfs.c | 3 +++ src/mount_davfs.h | 1 + src/webdav.c | 16 +++++++++++++++- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 113b691..b37d917 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,14 @@ ChangeLog for davfs2 -------------------- +2014-03-11 Werner Baumann (werner.baumann@onlinehome.de) + * defaults.h, mount_davfs.h, mount_davfs.c, wedav.c: + Support compression for GET responses (bug #41355, + thanks Evili del Rio). + 2014-03-09 Werner Baumann (werner.baumann@onlinehome.de) * mount_davfs.c, get_options: - Add option "comment=" (bug #41354) + Add option "comment=" (bug #41354). 2013-09-08 Werner Baumann (werner.baumann@onlinehome.de) * Updating to fuse kernel version 7.19. diff --git a/src/defaults.h b/src/defaults.h index 41f7459..204f0b6 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -174,6 +174,9 @@ May be overridden by system config file and user config file. */ #define DAV_IGNORE_DAV_HEADER 0 +/* Use "Content-Encoding: gzip" for GET requests. */ +#define DAV_USE_COMPRESSION 1 + /* Timeout in seconds used when libneon supports non blocking io A value of zero means use the TCP default May be overriden by system config file and user config file. */ diff --git a/src/mount_davfs.c b/src/mount_davfs.c index eca58e2..5c8497f 100644 --- a/src/mount_davfs.c +++ b/src/mount_davfs.c @@ -1607,6 +1607,7 @@ new_args(void) args->allow_cookie = DAV_ALLOW_COOKIE; args->precheck = DAV_PRECHECK; args->ignore_dav_header = DAV_IGNORE_DAV_HEADER; + args->use_compression = DAV_USE_COMPRESSION; args->connect_timeout = DAV_CONNECT_TIMEOUT; args->read_timeout = DAV_READ_TIMEOUT; args->retry = DAV_RETRY; @@ -2092,6 +2093,8 @@ read_config(dav_args *args, const char * filename, int system) args->precheck = arg_to_int(parmv[1], 10, parmv[0]); } else if (strcmp(parmv[0], "ignore_dav_header") == 0) { args->ignore_dav_header = arg_to_int(parmv[1], 10, parmv[0]); + } else if (strcmp(parmv[0], "use_compression") == 0) { + args->use_compression = arg_to_int(parmv[1], 10, parmv[0]); } else if (strcmp(parmv[0], "connect_timeout") == 0) { args->connect_timeout = arg_to_int(parmv[1], 10, parmv[0]); } else if (strcmp(parmv[0], "read_timeout") == 0) { diff --git a/src/mount_davfs.h b/src/mount_davfs.h index e314349..489619a 100644 --- a/src/mount_davfs.h +++ b/src/mount_davfs.h @@ -91,6 +91,7 @@ typedef struct { int allow_cookie; /* User config file, system config file */ int precheck; /* User config file, system config file */ int ignore_dav_header; /* User config file, system config file */ + int use_compression; /* User config file, system config file */ time_t connect_timeout; /* User config file, system config file */ time_t read_timeout; /* User config file, system config file */ time_t retry; /* User config file, system config file */ diff --git a/src/webdav.c b/src/webdav.c index b9e1a14..73cb4e2 100644 --- a/src/webdav.c +++ b/src/webdav.c @@ -62,6 +62,7 @@ #include #include +#include #include #include #include @@ -198,6 +199,9 @@ static int precheck; /* Ignore the information in the DAV-header because it is wrong. */ static int ignore_dav_header; +/* Use "Content-Encoding: gzip" for GET requests. */ +static int use_compression; + /* Will be set to 1 when dav_init_connection() succeeded. */ static int initialized; @@ -422,6 +426,7 @@ dav_init_webdav(dav_args *args) drop_weak_etags = args->drop_weak_etags; precheck = args->precheck; ignore_dav_header = args->ignore_dav_header; + use_compression = args->use_compression & ne_has_support(NE_FEATURE_ZLIB); } @@ -669,9 +674,18 @@ dav_get_file(const char *path, const char *cache_path, off_t *size, ne_add_request_header(req, "If-Modified-Since", mod_time); } - ne_add_response_body_reader(req, ne_accept_2xx, file_reader, &ctx); + ne_decompress *dc_state = NULL; + if (use_compression) { + dc_state = ne_decompress_reader(req, ne_accept_2xx, file_reader, &ctx); + } else { + ne_add_response_body_reader(req, ne_accept_2xx, file_reader, &ctx); + } ret = ne_request_dispatch(req); + + if (use_compression) + ne_decompress_destroy(dc_state); + ret = get_error(ret, "GET"); if (ctx.error) ret = ctx.error;