|
|
|
@ -49,6 +49,7 @@ typedef struct {
|
|
|
|
|
buffer *compress_cache_dir;
|
|
|
|
|
array *compress;
|
|
|
|
|
off_t compress_max_filesize; /** max filesize in kb */
|
|
|
|
|
int allowed_encodings;
|
|
|
|
|
} plugin_config;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
@ -154,6 +155,7 @@ SETDEFAULTS_FUNC(mod_compress_setdefaults) {
|
|
|
|
|
{ "compress.cache-dir", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
|
|
|
|
|
{ "compress.filetype", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },
|
|
|
|
|
{ "compress.max-filesize", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
|
|
|
|
|
{ "compress.allowed-encodings", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },
|
|
|
|
|
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -161,15 +163,18 @@ SETDEFAULTS_FUNC(mod_compress_setdefaults) {
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < srv->config_context->used; i++) {
|
|
|
|
|
plugin_config *s;
|
|
|
|
|
array *encodings_arr = array_init();
|
|
|
|
|
|
|
|
|
|
s = calloc(1, sizeof(plugin_config));
|
|
|
|
|
s->compress_cache_dir = buffer_init();
|
|
|
|
|
s->compress = array_init();
|
|
|
|
|
s->compress_max_filesize = 0;
|
|
|
|
|
s->allowed_encodings = 0;
|
|
|
|
|
|
|
|
|
|
cv[0].destination = s->compress_cache_dir;
|
|
|
|
|
cv[1].destination = s->compress;
|
|
|
|
|
cv[2].destination = &(s->compress_max_filesize);
|
|
|
|
|
cv[3].destination = encodings_arr; /* temp array for allowed encodings list */
|
|
|
|
|
|
|
|
|
|
p->config_storage[i] = s;
|
|
|
|
|
|
|
|
|
@ -177,6 +182,39 @@ SETDEFAULTS_FUNC(mod_compress_setdefaults) {
|
|
|
|
|
return HANDLER_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (encodings_arr->used) {
|
|
|
|
|
size_t j = 0;
|
|
|
|
|
for (j = 0; j < encodings_arr->used; j++) {
|
|
|
|
|
data_string *ds = (data_string *)encodings_arr->data[j];
|
|
|
|
|
#ifdef USE_ZLIB
|
|
|
|
|
if (NULL != strstr(ds->value->ptr, "gzip"))
|
|
|
|
|
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
|
|
|
|
|
if (NULL != strstr(ds->value->ptr, "deflate"))
|
|
|
|
|
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_DEFLATE;
|
|
|
|
|
/*
|
|
|
|
|
if (NULL != strstr(ds->value->ptr, "compress"))
|
|
|
|
|
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_COMPRESS;
|
|
|
|
|
*/
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef USE_BZ2LIB
|
|
|
|
|
if (NULL != strstr(ds->value->ptr, "bzip2"))
|
|
|
|
|
s->allowed_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* default encodings */
|
|
|
|
|
s->allowed_encodings = 0
|
|
|
|
|
#ifdef USE_ZLIB
|
|
|
|
|
| HTTP_ACCEPT_ENCODING_GZIP | HTTP_ACCEPT_ENCODING_DEFLATE
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef USE_BZ2LIB
|
|
|
|
|
| HTTP_ACCEPT_ENCODING_BZIP2
|
|
|
|
|
#endif
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
array_free(encodings_arr);
|
|
|
|
|
|
|
|
|
|
if (!buffer_is_empty(s->compress_cache_dir)) {
|
|
|
|
|
struct stat st;
|
|
|
|
|
mkdir_recursive(s->compress_cache_dir->ptr);
|
|
|
|
@ -587,6 +625,7 @@ static int mod_compress_patch_connection(server *srv, connection *con, plugin_da
|
|
|
|
|
PATCH(compress_cache_dir);
|
|
|
|
|
PATCH(compress);
|
|
|
|
|
PATCH(compress_max_filesize);
|
|
|
|
|
PATCH(allowed_encodings);
|
|
|
|
|
|
|
|
|
|
/* skip the first, the global context */
|
|
|
|
|
for (i = 1; i < srv->config_context->used; i++) {
|
|
|
|
@ -606,6 +645,8 @@ static int mod_compress_patch_connection(server *srv, connection *con, plugin_da
|
|
|
|
|
PATCH(compress);
|
|
|
|
|
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.max-filesize"))) {
|
|
|
|
|
PATCH(compress_max_filesize);
|
|
|
|
|
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.allowed-encodings"))) {
|
|
|
|
|
PATCH(allowed_encodings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -668,27 +709,21 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
|
|
|
|
|
if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "Accept-Encoding"))) {
|
|
|
|
|
int accept_encoding = 0;
|
|
|
|
|
char *value = ds->value->ptr;
|
|
|
|
|
int srv_encodings = 0;
|
|
|
|
|
int matched_encodings = 0;
|
|
|
|
|
|
|
|
|
|
/* get client side support encodings */
|
|
|
|
|
#ifdef USE_ZLIB
|
|
|
|
|
if (NULL != strstr(value, "gzip")) accept_encoding |= HTTP_ACCEPT_ENCODING_GZIP;
|
|
|
|
|
if (NULL != strstr(value, "deflate")) accept_encoding |= HTTP_ACCEPT_ENCODING_DEFLATE;
|
|
|
|
|
if (NULL != strstr(value, "compress")) accept_encoding |= HTTP_ACCEPT_ENCODING_COMPRESS;
|
|
|
|
|
if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
|
|
|
|
|
if (NULL != strstr(value, "identity")) accept_encoding |= HTTP_ACCEPT_ENCODING_IDENTITY;
|
|
|
|
|
|
|
|
|
|
/* get server side supported ones */
|
|
|
|
|
#ifdef USE_BZ2LIB
|
|
|
|
|
srv_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef USE_ZLIB
|
|
|
|
|
srv_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
|
|
|
|
|
srv_encodings |= HTTP_ACCEPT_ENCODING_DEFLATE;
|
|
|
|
|
#ifdef USE_BZ2LIB
|
|
|
|
|
if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
|
|
|
|
|
#endif
|
|
|
|
|
if (NULL != strstr(value, "identity")) accept_encoding |= HTTP_ACCEPT_ENCODING_IDENTITY;
|
|
|
|
|
|
|
|
|
|
/* find matching entries */
|
|
|
|
|
matched_encodings = accept_encoding & srv_encodings;
|
|
|
|
|
matched_encodings = accept_encoding & p->conf.allowed_encodings;
|
|
|
|
|
|
|
|
|
|
if (matched_encodings) {
|
|
|
|
|
const char *dflt_gzip = "gzip";
|
|
|
|
|