Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 952DE200B95 for ; Tue, 27 Sep 2016 18:13:45 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 93BAF160AD2; Tue, 27 Sep 2016 16:13:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B115B160AB9 for ; Tue, 27 Sep 2016 18:13:44 +0200 (CEST) Received: (qmail 48818 invoked by uid 500); 27 Sep 2016 16:13:43 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 48802 invoked by uid 99); 27 Sep 2016 16:13:43 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Sep 2016 16:13:43 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 295CB1A547B for ; Tue, 27 Sep 2016 16:13:43 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.426 X-Spam-Level: X-Spam-Status: No, score=-0.426 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id WDJ5KgV1m0Zk for ; Tue, 27 Sep 2016 16:13:42 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 678315FE2A for ; Tue, 27 Sep 2016 16:13:41 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 8C732E0147 for ; Tue, 27 Sep 2016 16:13:40 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 8284C3A0478 for ; Tue, 27 Sep 2016 16:13:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1762512 - /httpd/httpd/trunk/modules/filters/mod_brotli.c Date: Tue, 27 Sep 2016 16:13:39 -0000 To: cvs@httpd.apache.org From: kotkov@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160927161339.8284C3A0478@svn01-us-west.apache.org> archived-at: Tue, 27 Sep 2016 16:13:45 -0000 Author: kotkov Date: Tue Sep 27 16:13:38 2016 New Revision: 1762512 URL: http://svn.apache.org/viewvc?rev=1762512&view=rev Log: mod_brotli: Allow compression ratio logging with new BrotliFilterNote directive. Modified: httpd/httpd/trunk/modules/filters/mod_brotli.c Modified: httpd/httpd/trunk/modules/filters/mod_brotli.c URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_brotli.c?rev=1762512&r1=1762511&r2=1762512&view=diff ============================================================================== --- httpd/httpd/trunk/modules/filters/mod_brotli.c (original) +++ httpd/httpd/trunk/modules/filters/mod_brotli.c Tue Sep 27 16:13:38 2016 @@ -34,6 +34,9 @@ typedef struct brotli_server_config_t { int lgwin; int lgblock; etag_mode_e etag_mode; + const char *note_ratio_name; + const char *note_input_name; + const char *note_output_name; } brotli_server_config_t; static void *create_server_config(apr_pool_t *p, server_rec *s) @@ -56,6 +59,34 @@ static void *create_server_config(apr_po return conf; } +static const char *set_filter_note(cmd_parms *cmd, void *dummy, + const char *arg1, const char *arg2) +{ + brotli_server_config_t *conf = + ap_get_module_config(cmd->server->module_config, &brotli_module); + + if (!arg2) { + conf->note_ratio_name = arg1; + return NULL; + } + + if (ap_cstr_casecmp(arg1, "Ratio") == 0) { + conf->note_ratio_name = arg2; + } + else if (ap_cstr_casecmp(arg1, "Input") == 0) { + conf->note_input_name = arg2; + } + else if (ap_cstr_casecmp(arg1, "Output") == 0) { + conf->note_output_name = arg2; + } + else { + return apr_psprintf(cmd->pool, "Unknown BrotliFilterNote type '%s'", + arg1); + } + + return NULL; +} + static const char *set_compression_quality(cmd_parms *cmd, void *dummy, const char *arg) { @@ -126,6 +157,8 @@ static const char *set_etag_mode(cmd_par typedef struct brotli_ctx_t { BrotliEncoderState *state; apr_bucket_brigade *bb; + apr_off_t total_in; + apr_off_t total_out; } brotli_ctx_t; static void *alloc_func(void *opaque, size_t size) @@ -164,6 +197,8 @@ static brotli_ctx_t *create_ctx(int qual apr_pool_cleanup_register(pool, ctx, cleanup_ctx, apr_pool_cleanup_null); ctx->bb = apr_brigade_create(pool, alloc); + ctx->total_in = 0; + ctx->total_out = 0; return ctx; } @@ -203,6 +238,8 @@ static apr_status_t process_chunk(brotli * ap_pass_brigade() call. */ output = BrotliEncoderTakeOutput(ctx->state, &output_len); + ctx->total_out += output_len; + b = apr_bucket_transient_create(output, output_len, ctx->bb->bucket_alloc); APR_BRIGADE_INSERT_TAIL(ctx->bb, b); @@ -215,6 +252,7 @@ static apr_status_t process_chunk(brotli } } + ctx->total_in += len; return APR_SUCCESS; } @@ -249,6 +287,8 @@ static apr_status_t flush(brotli_ctx_t * */ output_len = 0; output = BrotliEncoderTakeOutput(ctx->state, &output_len); + ctx->total_out += output_len; + b = apr_bucket_heap_create(output, output_len, NULL, ctx->bb->bucket_alloc); APR_BRIGADE_INSERT_TAIL(ctx->bb, b); @@ -440,6 +480,27 @@ static apr_status_t compress_filter(ap_f return rv; } + /* Leave notes for logging. */ + if (conf->note_input_name) { + apr_table_setn(r->notes, conf->note_input_name, + apr_off_t_toa(r->pool, ctx->total_in)); + } + if (conf->note_output_name) { + apr_table_setn(r->notes, conf->note_output_name, + apr_off_t_toa(r->pool, ctx->total_out)); + } + if (conf->note_ratio_name) { + if (ctx->total_in > 0) { + int ratio = (int) (ctx->total_out * 100 / ctx->total_in); + + apr_table_setn(r->notes, conf->note_ratio_name, + apr_itoa(r->pool, ratio)); + } + else { + apr_table_setn(r->notes, conf->note_ratio_name, "-"); + } + } + APR_BUCKET_REMOVE(e); APR_BRIGADE_INSERT_TAIL(ctx->bb, e); @@ -492,6 +553,9 @@ static void register_hooks(apr_pool_t *p } static const command_rec cmds[] = { + AP_INIT_TAKE12("BrotliFilterNote", set_filter_note, + NULL, RSRC_CONF, + "Set a note to report on compression ratio"), AP_INIT_TAKE1("BrotliCompressionQuality", set_compression_quality, NULL, RSRC_CONF, "Compression quality between 0 and 11 (higher quality means "