Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Users

RequestHeader, SetEnvIf: Setting a missing RequestHeader

 

 

Apache users RSS feed   Index | Next | Previous | View Threaded


bargholz at onlinetravel

Mar 30, 2012, 5:16 AM

Post #1 of 3 (788 views)
Permalink
RequestHeader, SetEnvIf: Setting a missing RequestHeader

Hi,

After googling and experimenting all morning, perhaps some kind soul would be willing to help.

We have a web service that is routed through an Apache 2.2 on Windows. A correct SOAP Request would be

POST http://myapache/cgi-bin/nph-owscgi.exe/olt_web/oltlogon HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://127.0.0.1:5912"

<soapenv:Envelope ...>
...
</soapenv:Envelope>

Note the SOAPAction RequestHeader. This tells the "nph-owscgi.exe" where to send the request so that the application server can process the request.

Some customers do not send us a SOAPHeader. In this case we would like to automatically set the SOAPHeader RequestHeader value.

Here an example of a Reqeust without a SOAPHeader:

POST http://myapache/cgi-bin/nph-owscgi.exe/olt_web/oltlogon HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""

<soapenv:Envelope ...>
...
</soapenv:Envelope>

or

POST http://myapache/cgi-bin/nph-owscgi.exe/olt_web/oltlogon HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8

<soapenv:Envelope ...>
...
</soapenv:Envelope>

Goal: to automatically set the SOAPAction if empty or missing.

Here what I would expect to work, but does not.

<Files "nph-owscgi.exe">
SetEnvIf SOAPAction ^h.*$ HAVE_SOAPAction
RequestHeader set SOAPAction "http://127.0.0.1:5912" env=!HAVE_SOAPAction
</Files>

What I am trying to tell Apache is, if the SOAPAction RequestHeader starts with an "h", then set the environment variable HAVE_SOAPAction. If the environment variable HAVE_SOAPAction is not set, then set the SOAPAction ReqeustHeader to the default value of "http://127.0.0.1:5912".

Tried other

Unfortunately this is not working. The SOAPAction is always being overwritten, not just if empty or missing from the request headers.

Any tips what I am doing wrong?

Regards

Rudolf


Bruno.Treguier at shom

Mar 30, 2012, 5:48 AM

Post #2 of 3 (767 views)
Permalink
Re: RequestHeader, SetEnvIf: Setting a missing RequestHeader [In reply to]

Le 30/03/2012 14:16, Rudolf Bargholz a écrit :

> Goal: to automatically set the SOAPAction if empty or missing.
>
> Here what I would expect to work, but does not.
>
> <Files "nph-owscgi.exe">
>
> SetEnvIf SOAPAction ^h.*$ HAVE_SOAPAction
>
> RequestHeader set SOAPAction "http://127.0.0.1:5912" env=!HAVE_SOAPAction
>
> </Files>
>
> What I am trying to tell Apache is, if the SOAPAction RequestHeader
> starts with an “h”, then set the environment variable HAVE_SOAPAction.
> If the environment variable HAVE_SOAPAction is not set, then set the
> SOAPAction ReqeustHeader to the default value of "http://127.0.0.1:5912".
>
> Tried other
>
> Unfortunately this is not working. The SOAPAction is always being
> overwritten, not just if empty or missing from the request headers.
>
> Any tips what I am doing wrong?

Hi Rudolf,

AFAIK, SetEnvIf's first argument is supposed to be a standard header
name (listed in RFC2616) or an environment variable. I'm wondering
whether your SOAPAction custom header is really taken into account as an
environment variable. It seems that it's not the case, so maybe you
could try to set an environment variable based on your header, by using
a side effect of a RewriteRule ("E" flag) and then using that variable
in your test ?

Here is how I would do that:

RewriteEngine on
RewriteRule .* - [E=SOAPAction:%{HTTP:SOAPAction}]

Then you might be able to use the SOAPAction *environment variable*
which will have the same value as the SOAPAction *HTTP header*

Could you try that ?

Best regards,

Bruno

--
- Service Hydrographique et Oceanographique de la Marine - DMGS/INF
- 13, rue du Chatellier - CS 92803 - 29228 Brest Cedex 2, FRANCE
- Phone: +33 2 98 22 17 49 - Email: Bruno.Treguier [at] shom

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd


bargholz at onlinetravel

Mar 30, 2012, 6:55 AM

Post #3 of 3 (806 views)
Permalink
AW: RequestHeader, SetEnvIf: Setting a missing RequestHeader [In reply to]

Le 30/03/2012 14:16, Rudolf Bargholz a écrit :

> Goal: to automatically set the SOAPAction if empty or missing.
>
> Here what I would expect to work, but does not.
>
> <Files "nph-owscgi.exe">
>
> SetEnvIf SOAPAction ^h.*$ HAVE_SOAPAction
>
> RequestHeader set SOAPAction "http://127.0.0.1:5912"
> env=!HAVE_SOAPAction
>
> </Files>
>
> What I am trying to tell Apache is, if the SOAPAction RequestHeader
> starts with an "h", then set the environment variable HAVE_SOAPAction.
> If the environment variable HAVE_SOAPAction is not set, then set the
> SOAPAction ReqeustHeader to the default value of "http://127.0.0.1:5912".
>
> Tried other
>
> Unfortunately this is not working. The SOAPAction is always being
> overwritten, not just if empty or missing from the request headers.
>
> Any tips what I am doing wrong?

Hi Rudolf,

AFAIK, SetEnvIf's first argument is supposed to be a standard header name (listed in RFC2616) or an environment variable. I'm wondering whether your SOAPAction custom header is really taken into account as an environment variable. It seems that it's not the case, so maybe you could try to set an environment variable based on your header, by using a side effect of a RewriteRule ("E" flag) and then using that variable in your test ?

Here is how I would do that:

RewriteEngine on
RewriteRule .* - [E=SOAPAction:%{HTTP:SOAPAction}]

Then you might be able to use the SOAPAction *environment variable* which will have the same value as the SOAPAction *HTTP header*



Hi Bruno,

Thanks for taking the time to help.

Turned on mod_rewrite by uncommenting it in the httpd.conf, added " Options +FollowSymlinks" to my ".htaccess", and then tested the following:

<Files "nph-owscgi.exe">
RewriteEngine on
RewriteRule .* - [E=SOAPAction:%{HTTP:SOAPAction}]
SetEnvIf SOAPAction ^(http) HAVE_SOAPAction
RequestHeader set SOAPAction "http://127.0.0.1:5912" env=!HAVE_SOAPAction
</Files>

No error returned.

Then tested what would happen if I change the port to an invalid port. If a valid SOAPAction is supplied, this ought not have any effect on the result. It still ought to work correctly. The case where the SOAPAction is missing or empty would however report an error. My test determined that if I changed the conf to

<Files "nph-owscgi.exe">
RewriteEngine on
RewriteRule .* - [E=SOAPAction:%{HTTP:SOAPAction}]
SetEnvIf SOAPAction ^(http) HAVE_SOAPAction
RequestHeader set SOAPAction "http://127.0.0.1:5912" env=!HAVE_SOAPAction
</Files>

then in both cases the web service returns an error. So even in the case where I have a SOAPAction, it is being overwritten by the httpd.conf.

So no, this did not work, or I am doing something wrong, which is very likely.

Regards

Rudolf



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd

Apache users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.