Can not use $bytes_sent in module (complex values)
Vladimir Shebordaev
vshebordaev at mail.ru
Wed Sep 19 23:43:20 UTC 2012
Wed, 19 Sep 2012 23:11:57 +0200 от Benjamin Grössing <mailtogroe at gmail.com>:
>2012/9/20 Benjamin Grössing <mailtogroe at gmail.com>:
>
>Hi Vladimir, hi Maxim!
>
>Thanks for your answers. I've had a look at the rewrite module -
>unfortunately it does not support the $bytes_sent variable either as
>configuring "if ($bytes_sent) { }" throws the error: [emerg] unknown
>"bytes_sent" variable.
Yes, this is what the indexed variables are. They have no name at runtime and accessed by the index into the request->variables array by the script engine that is to evaluate a complex value and if conditionals. This is faster to do, since it helps to avoid the cmcf->variables_hash lookup and a memory allocation at evaluation time having the space for the value reserved at the request initialization time. But the index value must be known to the rewrite module at the configuration time.
>Nice to hear that there is a plan to include all variables in the
>complex value system - I think that would make that part a of nginx a
>lot more clear! I'd be happy if I could contribute here, but I am not
One way to make the log module varaibles known to the rewite module is to register 'em with ngx_http_add_variable(). But this way they loose in performance, not to say this would be not quite consistent with their semantics that is "automatic" wrt the request.
Another way is to make the log module use cmcf->variables as the global registry for the indexed variables just like the rewrite module does, and only rely on the script engine to evaluate 'em. This way the log module variables would be available to rewrite module remaining the light-weight indexed ones. This will also help to avoid the dependency on the module initialization sequence.
>sure about the details. Is there any guide to contributing to nginx
>available or do I just have to create a patch file and post it here?
>Can I just start with the nginx 1.2.3 source code from nginx.org?
>
>
I guess the patch sent to this list would do as long as it applies to any svn branch. The code base will change while you are working on the feature, so your patch will anyways have to be merged.
Regards,
Vladimir
>Regards
>
Benjamin
>
>
2012/9/19 Maxim Dounin <mdounin at mdounin.ru>:
>
> Hello!
>
>
>
> On Tue, Sep 18, 2012 at 03:55:38PM +0200, Benjamin Grössing wrote:
>
>
>
>> Hello,
>
>>
>
>> I am currently working on a nginx module, that parses user defined
>
>> strings for variables using ngx_http_complex_value_t. That works great
>
>> with all variables defined in ngx_http_variables.c (i.e.
>
>> $body_bytes_sent). However, variables as $bytes_sent do not exist here
>
>> since ngx_http_log_module uses its own variable parsing system. What
>
>> is the best way to use these extra variables in my module? I have
>
>> thought of the following options, I am not very sure about what is the
>
>> best way to go:
>
>> a) Copy the ngx_http_log_module code in my own module and rename every
>
>> single type and function to avoid double definitions. Reuse functions
>
>> and types from there.
>
>> b) Move the ngx_http_log_module code in my own module directory and
>
>> compile it only there. Reuse functions and types from there.
>
>> c) Write own variable parsing system, reuse a few snippets from
>
>> ngx_http_variables and ngx_http_log_module, whatever fits best.
>
>> d) Use complex values and try to extend the ngx_http_core_variables
>
>> array to include $body_bytes_sent and the other missing variables (I
>
>> don't understand why they are not included here anyway?).
>
>> e) Any better way to achieve that?
>
>>
>
>> I'd really appreciate your help.
>
>
>
> All variables that are currently present only in log module should
>
> really be made available as normal variables as well. They aren't
>
> yet mostly due to historical reasons (log module appeared before
>
> normal variables were implemented) and the fact that most of
>
> them are only usable for logging.
>
>
>
> No idea what would be best for your particular module, but in
>
> general it's better to use complex values and what's available via
>
> normal variables. Unless you need $bytes_sent right now - it's
>
> probably the best aproach, and missing variables will be available
>
> once they appear in nginx.
>
>
>
> (The latter is something you may speedup by submitting a good
>
> patch. Most tricky part here would be to follow coding style.)
>
>
>
> Maxim Dounin
>
>
>
> _______________________________________________
>
> nginx-devel mailing list
>
> nginx-devel at nginx.org
>
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
>
_______________________________________________
>
nginx-devel mailing list
>nginx-devel at nginx.org
>http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20120920/5d74b265/attachment-0001.html>
More information about the nginx-devel
mailing list