You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Rudolf Bargholz <ba...@onlinetravel.ch> on 2012/03/30 14:16:33 UTC

[users@httpd] 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

AW: [users@httpd] RequestHeader, SetEnvIf: Setting a missing RequestHeader

Posted by Rudolf Bargholz <ba...@onlinetravel.ch>.
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@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RequestHeader, SetEnvIf: Setting a missing RequestHeader

Posted by Bruno Tréguier <Br...@shom.fr>.
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@shom.fr

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