You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Martin Knoblauch <kn...@knobisoft.de> on 2018/03/22 16:23:37 UTC

[users@httpd] How to print request headers before and after processing

Hi,

 so I need some little help. I need to modify request headers in some
situations and for debugging, I want to print the content of the header
before and after processing. So I looked at mod_log_config and found:

----
%{VARNAME}i : The contents of VARNAME: header line(s) in the request sent
to the server. Changes made by other modules (e.g. mod_headers
<http://httpd.apache.org/docs/current/mod/mod_headers.html>) affect this.
If you're interested in what the request header was prior to when most
modules would have modified it, use mod_setenvif
<http://httpd.apache.org/docs/current/mod/mod_setenvif.html> to copy the
header into an internal environment variable and log that value with the %{
VARNAME}e described above.
----

 And actually %{varname}i prints out the processed request header. Where I
have problems is the "use mod_setenvif
<http://httpd.apache.org/docs/current/mod/mod_setenvif.html> to copy the
header into an internal environment variable" part. The request header in
question is "Cookie". So I tried to do the following:

a) in httpd.conf

    LogFormat "%t [%{ms}T ms] %h %u \"%m %U '%{login_jsid}e' '%{Cookie}i'\"
s:%>s l:%b S:%{SSL_PROTOCOL}x C:%{SSL_CIPHER}x" xxxlogheader

b) in the virtual host

    SetEnvIfExpr "%{REQUEST_URI} == '/cb2/facelets/logon.xhtml' &&
%{REQUEST_METHOD} == 'GET'" login_get login_jsid=%{HTTP_COOKIE}e
    CustomLog "..../apache2/logs/login_log" xxxlogheader env=login_get

So I would actually expect the content of the Cookie  being printed twice
when doing no additional processing. Instead I get:

   "GET /xxx/facelets/logon.xhtml '%{HTTP_COOKIE}e' 'JSESSIONID=yyyyy;
/xxx_textLocale=en/US'"

 Which indicates that my assignment in the SetEnvIfExpr directive is wrong.
Any help how to get that right?

TIA
Martin
-- 
------------------------------------------------------
Martin Knoblauch
email: k n o b i AT knobisoft DOT de
www: http://www.knobisoft.de

Re: [users@httpd] How to print request headers before and after processing

Posted by Martin Knoblauch <kn...@knobisoft.de>.
Hi Rainer,

 thanks for the enlightenment :-) I was not aware, that the RewriteRule
check is done before actually evaluating the RewriteCond(s). So, out of
curiosity I gave it a try. As I only need to look for the GET request on
the login-page, this works fine for me:

RewriteCond "%{REQUEST_METHOD}" "GET"
RewriteRule ^/xxx/facelets/logon.xhtml$ - [E=login_jsid:%{HTTP_COOKIE}]


 Surprisingly, here I can use a variable in the assignment to "login_jsid"
:-) Otherwise, this would have worked as well:

RewriteCond "%{REQUEST_METHOD}" "GET"
RewriteCond "%{HTTP_COOKIE}" "(.*)"
RewriteRule ^/xxx/facelets/logon.xhtml$ - [E=login_jsid:%1]

Clearly, the logging is now much better than with the "forensic" stuff. Now
to the main task :-)

Cheers
Martin




On Thu, Mar 22, 2018 at 8:28 PM, Rainer Jung <ra...@kippdata.de>
wrote:

> Am 22.03.2018 um 18:56 schrieb Martin Knoblauch:
>
>> Hi Rainer,
>>
>>   unfortunately mod_log_debug seems to work only on directory scope, not
>> on virtual host.
>>
>
> But note, that <Location> is directory scope, for instance
>
> <Location /cb2/facelets/logon.xhtml>
>    ...
> </Location>
>
> And I considered the mod_rewrite thingy, but feared it to be to expensive.
>>
> >
>
>>   In the meantime I found "mod_log_forensic". Ugly, I do not know the
>> cost, but it works for my purpose.
>>
>
> I think mod_rewrite is not that expensive.
>
> When a RewriteCond and a RewriteRuke is combined, it will first check the
> left side of the RewriteRule against your URL. If it doesnt match, the
> RewriteCond and the flags are not evaluated. So it is important to not have
> a complex pattern in RewriteRule. In your case it is not complex.
>
> Then next te RewriteCond is checked. In your case picking one header and
> matching with ".*" which is also not very expensive (not backtracking).
>
> And then finally the env var setting. Performancewise this will be very
> close to the SetEnvIf variant.
>
> Regards,
>
> Rainer
>
> Thanks
>> Martin
>>
>> On Thu, Mar 22, 2018 at 6:16 PM, Rainer Jung <rainer.jung@kippdata.de
>> <ma...@kippdata.de>> wrote:
>>
>>     Am 22.03.2018 um 18:08 schrieb Eric Covener:
>>
>>         On Thu, Mar 22, 2018 at 1:03 PM, Martin Knoblauch
>>         <knobi@knobisoft.de <ma...@knobisoft.de>> wrote:
>>
>>             Hi Eric,
>>
>>                thanks, but does not work.
>>
>>             login_jsid=Cookie  prints "Cookie"
>>             login_jsid=%{Cookie} prints "%{Cookie}"
>>
>>             Apparently the right sides of the assignment are just taken
>>             as literals
>>             without evaluating them as variables.
>>
>>
>>         Arg, sorry, It is only for the first arg.
>>
>>             Had a brief look at mod_log_debug, but do not see how it
>>             helps me in this
>>             case.
>>
>>
>>         You could log expressions before/after the  your edits.
>>
>>
>>     ... by choosing different hooks.
>>
>>     If that does not work, you could also try to copy the header to an
>>     env var using mod_rewrite. Something like
>>
>>     RewriteCond "%{HTTP_COOKIE}" "(.*)"
>>     RewriteRule ^/cb2/facelets/logon.xhtml$ - [E=login_jsid:%1]
>>
>>     But you need to test. Not sure in what order the mod_headers
>>     replacement and the mod_rewrite rule handling run. I vaguely
>>     remember having used a trick like this.
>>
>>     Including your marker login_get should work like this:
>>
>>     RewriteCond "%{HTTP_COOKIE}" "(.*)"
>>     RewriteRule ^/cb2/facelets/logon.xhtml$ -
>> [E=login_jsid:%1,E=login_get]
>>
>>     Regards,
>>
>>     Rainer
>>
>>
>>
>>     ---------------------------------------------------------------------
>>     To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>     <ma...@httpd.apache.org>
>>     For additional commands, e-mail: users-help@httpd.apache.org
>>     <ma...@httpd.apache.org>
>>
>>
>>
>>
>> --
>> ------------------------------------------------------
>> Martin Knoblauch
>> email: k n o b i AT knobisoft DOT de
>> www: http://www.knobisoft.de
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 
------------------------------------------------------
Martin Knoblauch
email: k n o b i AT knobisoft DOT de
www: http://www.knobisoft.de

Re: [users@httpd] How to print request headers before and after processing

Posted by Rainer Jung <ra...@kippdata.de>.
Am 22.03.2018 um 18:56 schrieb Martin Knoblauch:
> Hi Rainer,
> 
>   unfortunately mod_log_debug seems to work only on directory scope, not 
> on virtual host. 

But note, that <Location> is directory scope, for instance

<Location /cb2/facelets/logon.xhtml>
    ...
</Location>

> And I considered the mod_rewrite thingy, but feared it 
> to be to expensive.
 >
>   In the meantime I found "mod_log_forensic". Ugly, I do not know the 
> cost, but it works for my purpose.

I think mod_rewrite is not that expensive.

When a RewriteCond and a RewriteRuke is combined, it will first check 
the left side of the RewriteRule against your URL. If it doesnt match, 
the RewriteCond and the flags are not evaluated. So it is important to 
not have a complex pattern in RewriteRule. In your case it is not complex.

Then next te RewriteCond is checked. In your case picking one header and 
matching with ".*" which is also not very expensive (not backtracking).

And then finally the env var setting. Performancewise this will be very 
close to the SetEnvIf variant.

Regards,

Rainer

> Thanks
> Martin
> 
> On Thu, Mar 22, 2018 at 6:16 PM, Rainer Jung <rainer.jung@kippdata.de 
> <ma...@kippdata.de>> wrote:
> 
>     Am 22.03.2018 um 18:08 schrieb Eric Covener:
> 
>         On Thu, Mar 22, 2018 at 1:03 PM, Martin Knoblauch
>         <knobi@knobisoft.de <ma...@knobisoft.de>> wrote:
> 
>             Hi Eric,
> 
>                thanks, but does not work.
> 
>             login_jsid=Cookie  prints "Cookie"
>             login_jsid=%{Cookie} prints "%{Cookie}"
> 
>             Apparently the right sides of the assignment are just taken
>             as literals
>             without evaluating them as variables.
> 
> 
>         Arg, sorry, It is only for the first arg.
> 
>             Had a brief look at mod_log_debug, but do not see how it
>             helps me in this
>             case.
> 
> 
>         You could log expressions before/after the  your edits.
> 
> 
>     ... by choosing different hooks.
> 
>     If that does not work, you could also try to copy the header to an
>     env var using mod_rewrite. Something like
> 
>     RewriteCond "%{HTTP_COOKIE}" "(.*)"
>     RewriteRule ^/cb2/facelets/logon.xhtml$ - [E=login_jsid:%1]
> 
>     But you need to test. Not sure in what order the mod_headers
>     replacement and the mod_rewrite rule handling run. I vaguely
>     remember having used a trick like this.
> 
>     Including your marker login_get should work like this:
> 
>     RewriteCond "%{HTTP_COOKIE}" "(.*)"
>     RewriteRule ^/cb2/facelets/logon.xhtml$ - [E=login_jsid:%1,E=login_get]
> 
>     Regards,
> 
>     Rainer
> 
> 
> 
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>     <ma...@httpd.apache.org>
>     For additional commands, e-mail: users-help@httpd.apache.org
>     <ma...@httpd.apache.org>
> 
> 
> 
> 
> -- 
> ------------------------------------------------------
> Martin Knoblauch
> email: k n o b i AT knobisoft DOT de
> www: http://www.knobisoft.de

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to print request headers before and after processing

Posted by Martin Knoblauch <kn...@knobisoft.de>.
Hi Rainer,

 unfortunately mod_log_debug seems to work only on directory scope, not on
virtual host. And I considered the mod_rewrite thingy, but feared it to be
to expensive.

 In the meantime I found "mod_log_forensic". Ugly, I do not know the cost,
but it works for my purpose.

Thanks
Martin

On Thu, Mar 22, 2018 at 6:16 PM, Rainer Jung <ra...@kippdata.de>
wrote:

> Am 22.03.2018 um 18:08 schrieb Eric Covener:
>
>> On Thu, Mar 22, 2018 at 1:03 PM, Martin Knoblauch <kn...@knobisoft.de>
>> wrote:
>>
>>> Hi Eric,
>>>
>>>   thanks, but does not work.
>>>
>>> login_jsid=Cookie  prints "Cookie"
>>> login_jsid=%{Cookie} prints "%{Cookie}"
>>>
>>> Apparently the right sides of the assignment are just taken as literals
>>> without evaluating them as variables.
>>>
>>>
>> Arg, sorry, It is only for the first arg.
>>
>> Had a brief look at mod_log_debug, but do not see how it helps me in this
>>> case.
>>>
>>
>> You could log expressions before/after the  your edits.
>>
>
> ... by choosing different hooks.
>
> If that does not work, you could also try to copy the header to an env var
> using mod_rewrite. Something like
>
> RewriteCond "%{HTTP_COOKIE}" "(.*)"
> RewriteRule ^/cb2/facelets/logon.xhtml$ - [E=login_jsid:%1]
>
> But you need to test. Not sure in what order the mod_headers replacement
> and the mod_rewrite rule handling run. I vaguely remember having used a
> trick like this.
>
> Including your marker login_get should work like this:
>
> RewriteCond "%{HTTP_COOKIE}" "(.*)"
> RewriteRule ^/cb2/facelets/logon.xhtml$ - [E=login_jsid:%1,E=login_get]
>
> Regards,
>
> Rainer
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 
------------------------------------------------------
Martin Knoblauch
email: k n o b i AT knobisoft DOT de
www: http://www.knobisoft.de

Re: [users@httpd] How to print request headers before and after processing

Posted by Rainer Jung <ra...@kippdata.de>.
Am 22.03.2018 um 18:08 schrieb Eric Covener:
> On Thu, Mar 22, 2018 at 1:03 PM, Martin Knoblauch <kn...@knobisoft.de> wrote:
>> Hi Eric,
>>
>>   thanks, but does not work.
>>
>> login_jsid=Cookie  prints "Cookie"
>> login_jsid=%{Cookie} prints "%{Cookie}"
>>
>> Apparently the right sides of the assignment are just taken as literals
>> without evaluating them as variables.
>>
> 
> Arg, sorry, It is only for the first arg.
> 
>> Had a brief look at mod_log_debug, but do not see how it helps me in this
>> case.
> 
> You could log expressions before/after the  your edits.

... by choosing different hooks.

If that does not work, you could also try to copy the header to an env 
var using mod_rewrite. Something like

RewriteCond "%{HTTP_COOKIE}" "(.*)"
RewriteRule ^/cb2/facelets/logon.xhtml$ - [E=login_jsid:%1]

But you need to test. Not sure in what order the mod_headers replacement 
and the mod_rewrite rule handling run. I vaguely remember having used a 
trick like this.

Including your marker login_get should work like this:

RewriteCond "%{HTTP_COOKIE}" "(.*)"
RewriteRule ^/cb2/facelets/logon.xhtml$ - [E=login_jsid:%1,E=login_get]

Regards,

Rainer


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to print request headers before and after processing

Posted by Eric Covener <co...@gmail.com>.
On Thu, Mar 22, 2018 at 1:03 PM, Martin Knoblauch <kn...@knobisoft.de> wrote:
> Hi Eric,
>
>  thanks, but does not work.
>
> login_jsid=Cookie  prints "Cookie"
> login_jsid=%{Cookie} prints "%{Cookie}"
>
> Apparently the right sides of the assignment are just taken as literals
> without evaluating them as variables.
>

Arg, sorry, It is only for the first arg.

> Had a brief look at mod_log_debug, but do not see how it helps me in this
> case.

You could log expressions before/after the  your edits.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to print request headers before and after processing

Posted by Martin Knoblauch <kn...@knobisoft.de>.
Hi Eric,

 thanks, but does not work.

login_jsid=Cookie  prints "Cookie"
login_jsid=%{Cookie} prints "%{Cookie}"

Apparently the right sides of the assignment are just taken as literals
without evaluating them as variables.

Had a brief look at mod_log_debug, but do not see how it helps me in this
case.

Thanks
Martin

On Thu, Mar 22, 2018 at 5:50 PM, Eric Covener <co...@gmail.com> wrote:

> On Thu, Mar 22, 2018 at 12:50 PM, Eric Covener <co...@gmail.com> wrote:
> > have you looked at mod_log_debug?
> >
> >>     SetEnvIfExpr "%{REQUEST_URI} == '/cb2/facelets/logon.xhtml' &&
> %{REQUEST_METHOD} == 'GET'" login_get login_jsid=%{HTTP_COOKIE}e
> >
> > is the last token  of the above line wrong? Shouldn't it just be
> "Coookie"?
>
> w/o the extra o.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 
------------------------------------------------------
Martin Knoblauch
email: k n o b i AT knobisoft DOT de
www: http://www.knobisoft.de

Re: [users@httpd] How to print request headers before and after processing

Posted by Eric Covener <co...@gmail.com>.
On Thu, Mar 22, 2018 at 12:50 PM, Eric Covener <co...@gmail.com> wrote:
> have you looked at mod_log_debug?
>
>>     SetEnvIfExpr "%{REQUEST_URI} == '/cb2/facelets/logon.xhtml' && %{REQUEST_METHOD} == 'GET'" login_get login_jsid=%{HTTP_COOKIE}e
>
> is the last token  of the above line wrong? Shouldn't it just be "Coookie"?

w/o the extra o.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to print request headers before and after processing

Posted by Eric Covener <co...@gmail.com>.
have you looked at mod_log_debug?

>     SetEnvIfExpr "%{REQUEST_URI} == '/cb2/facelets/logon.xhtml' && %{REQUEST_METHOD} == 'GET'" login_get login_jsid=%{HTTP_COOKIE}e

is the last token  of the above line wrong? Shouldn't it just be "Coookie"?

On Thu, Mar 22, 2018 at 12:23 PM, Martin Knoblauch <kn...@knobisoft.de> wrote:
> Hi,
>
>  so I need some little help. I need to modify request headers in some
> situations and for debugging, I want to print the content of the header
> before and after processing. So I looked at mod_log_config and found:
>
> ----
> %{VARNAME}i : The contents of VARNAME: header line(s) in the request sent to
> the server. Changes made by other modules (e.g. mod_headers) affect this. If
> you're interested in what the request header was prior to when most modules
> would have modified it, use mod_setenvif to copy the header into an internal
> environment variable and log that value with the %{VARNAME}e described
> above.
> ----
>
>  And actually %{varname}i prints out the processed request header. Where I
> have problems is the "use mod_setenvif to copy the header into an internal
> environment variable" part. The request header in question is "Cookie". So I
> tried to do the following:
>
> a) in httpd.conf
>
>     LogFormat "%t [%{ms}T ms] %h %u \"%m %U '%{login_jsid}e' '%{Cookie}i'\"
> s:%>s l:%b S:%{SSL_PROTOCOL}x C:%{SSL_CIPHER}x" xxxlogheader
>
> b) in the virtual host
>
>     SetEnvIfExpr "%{REQUEST_URI} == '/cb2/facelets/logon.xhtml' &&
> %{REQUEST_METHOD} == 'GET'" login_get login_jsid=%{HTTP_COOKIE}e
>     CustomLog "..../apache2/logs/login_log" xxxlogheader env=login_get
>
> So I would actually expect the content of the Cookie  being printed twice
> when doing no additional processing. Instead I get:
>
>    "GET /xxx/facelets/logon.xhtml '%{HTTP_COOKIE}e' 'JSESSIONID=yyyyy;
> /xxx_textLocale=en/US'"
>
>  Which indicates that my assignment in the SetEnvIfExpr directive is wrong.
> Any help how to get that right?
>
> TIA
> Martin
> --
> ------------------------------------------------------
> Martin Knoblauch
> email: k n o b i AT knobisoft DOT de
> www: http://www.knobisoft.de



-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org