You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Tushar Joshi <tj...@turtle.net> on 2009/12/31 02:44:50 UTC

[users@httpd] Getting HTTP Headers from CGI program

Hi, 

I'm trying to get a HTTP header from my CGI program, in this particular
example it's SOAPAction, however I'm not sure how to do this as you can
only getenv some of the headers. Is there a way to get all the headers
sent from the client or a way in maybe the apache config to set the
environment variable manually. I've lookever all over for this and
couldn't find anything so either it's dead easy or I have to write an
apache module to do this?

Cheers if you can shed any light on this one, 


Tushar

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by André Warnier <aw...@ice-sa.com>.
Scott Gifford wrote:
> André Warnier <aw...@ice-sa.com> writes:
> 
>> Tushar Joshi wrote:
>>> Hi thanks for the reply. I'm writing my applications in C so would
>>> have thought there might be a low level way of doing this.
> 
> [...]
> 
>> But, in general, if this is a CGI program, then it is running as a
>> separate process from Apache itself, and it does not have access to
>> Apache internals.
>> What your program gets is the CGI environment as set up by Apache, but
>> you do not get all the HTTP request headers that way (only some are
>> "translated" by Apache as environment variables for your CGI
>> program).
> 
> It would be fairly straightforward to copy additional information from
> Apache to the environment with a little bit of mod_perl or a simple
> module, to make it available to CGI scripts.
> 
Allright, how ?  We're all ears.
If the OP does not use mod_perl right now, and this being the day which 
it is, I cannot for myself think of a quickie solution for the next 24 
hours or so...
  ;-)
Happy New Year.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by Scott Gifford <sg...@suspectclass.com>.
André Warnier <aw...@ice-sa.com> writes:

> Tushar Joshi wrote:
>> Hi thanks for the reply. I'm writing my applications in C so would
>> have thought there might be a low level way of doing this.

[...]

> But, in general, if this is a CGI program, then it is running as a
> separate process from Apache itself, and it does not have access to
> Apache internals.
> What your program gets is the CGI environment as set up by Apache, but
> you do not get all the HTTP request headers that way (only some are
> "translated" by Apache as environment variables for your CGI
> program).

It would be fairly straightforward to copy additional information from
Apache to the environment with a little bit of mod_perl or a simple
module, to make it available to CGI scripts.

----Scott.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by André Warnier <aw...@ice-sa.com>.
Tushar Joshi wrote:
> Hi thanks for the reply. I'm writing my applications in C so would have 
> thought there might be a low level way of doing this.
> 
I was asking, just in case you were using Perl.  I would then have 
pointed you to mod_perl and the CGI module, which together allow you to 
do that kind of thing easily.

But, in general, if this is a CGI program, then it is running as a 
separate process from Apache itself, and it does not have access to 
Apache internals.
What your program gets is the CGI environment as set up by Apache, but 
you do not get all the HTTP request headers that way (only some are 
"translated" by Apache as environment variables for your CGI program).

It would be different if your application, instead of a CGI program, was 
written as an Apache add-on module. That is possible, but I cannot help 
you there (other than with Perl).

There may be a possibility however, by using one of the existing Apache 
modules as a filter, which would take the content of a HTTP request 
header and turn it into an environment variable which your CGI could 
then see.
I cannot give you any specifics, but I would look at modules such as 
mod_setenvif, mod_headers, mod_rewrite.
I would start the search here :
http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html#setenvif

Be a bit careful however when you see words like "environment 
variables".  These words do not necessarily have the meaning 
"environment variables for CGI programs".


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by Tushar Joshi <tj...@turtle.net>.
Hi thanks for the reply. I'm writing my applications in C so would  
have thought there might be a low level way of doing this.


Turtle Networks

Tel +44 (0)20 8896 2600
www.turtle.net
Unit 48
Concord Road
London W3 0TH

On 31 Dec 2009, at 14:23, André Warnier <aw...@ice-sa.com> wrote:

> Tushar Joshi wrote:
>> Hi, I'm trying to get a HTTP header from my CGI program, in this  
>> particular
>> example it's SOAPAction, however I'm not sure how to do this as you  
>> can
>> only getenv some of the headers. Is there a way to get all the  
>> headers
>> sent from the client or a way in maybe the apache config to set the
>> environment variable manually. I've lookever all over for this and
>> couldn't find anything so either it's dead easy or I have to write an
>> apache module to do this?
>> Cheers if you can shed any light on this one,
> What is your CGI program written in ? (language)
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server  
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>  "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by André Warnier <aw...@ice-sa.com>.
Tushar Joshi wrote:
> Hi, 
> 
> I'm trying to get a HTTP header from my CGI program, in this particular
> example it's SOAPAction, however I'm not sure how to do this as you can
> only getenv some of the headers. Is there a way to get all the headers
> sent from the client or a way in maybe the apache config to set the
> environment variable manually. I've lookever all over for this and
> couldn't find anything so either it's dead easy or I have to write an
> apache module to do this?
> 
> Cheers if you can shed any light on this one, 
> 
What is your CGI program written in ? (language)

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by Eric Covener <co...@gmail.com>.
On Sat, Jan 2, 2010 at 6:42 AM, Tushar Joshi <tj...@turtle.net> wrote:

> I've had a look and SOAPAction seems to be an extension maybe of some
> sort as listed here
>
> http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528
>
> It just doesn't seem like apache has a way of getting the value of this
> header easily.

The CGI spec Nick is pointing you to says arbitrary headers are
already available in the env as HTTP_$headername.

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by Tushar Joshi <tj...@turtle.net>.
On Thu, Dec 31, 2009 at 06:45:51PM +0000, Nick Kew wrote:
> 
> On 31 Dec 2009, at 17:31, Tushar Joshi wrote:
> > 
> > Right bottom posting this time. I've looked in the manual searched on the web but I presume there isn't an easy way. I've looked at mod header and set env and I don't really want to add a perl wrapper to a lovely C program. I was hoping I could do something like getenv("HEADERS_REMAINING") or I could write an apache module to grab the SOAPAction header and set it in an environment variable.
> 
> If SOAPAction is an HTTP header, I suggest looking at the CGI spec
> (which is very, very simple) for how to get it.
> 

I've had a look and SOAPAction seems to be an extension maybe of some
sort as listed here

http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528

It just doesn't seem like apache has a way of getting the value of this
header easily. I've had a look at using mod_header/setenvif but I'm
hoping to have about 100 different values for SOAPAction. It seems I can
write an apache module to maybe do this:

HTTPHeader SOAPAction 

Which will convert the SOAPAction header to an environment variable 
HTTPHeader_SOAPAction and maybe the prefix can be defined as well. 

Tushar

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by Nick Kew <ni...@webthing.com>.
On 31 Dec 2009, at 17:31, Tushar Joshi wrote:
> 
> Right bottom posting this time. I've looked in the manual searched on the web but I presume there isn't an easy way. I've looked at mod header and set env and I don't really want to add a perl wrapper to a lovely C program. I was hoping I could do something like getenv("HEADERS_REMAINING") or I could write an apache module to grab the SOAPAction header and set it in an environment variable.

If SOAPAction is an HTTP header, I suggest looking at the CGI spec
(which is very, very simple) for how to get it.

-- 
Nick Kew

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by Eric Covener <co...@gmail.com>.
On Thu, Dec 31, 2009 at 12:31 PM, Tushar Joshi <tj...@turtle.net> wrote:
> was hoping I could do something like getenv("HEADERS_REMAINING") or I could
> write an apache module to grab the SOAPAction header and set it in an
> environment variable.

http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html#setenvif (or
mod_rewrite with E= flag)


-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by Tushar Joshi <tj...@turtle.net>.
On 31 Dec 2009, at 16:20, Nick Kew <ni...@webthing.com> wrote:

>
> On 31 Dec 2009, at 01:44, Tushar Joshi wrote:
>
>>
>> Hi,
>>
>> I'm trying to get a HTTP header from my CGI program, in this  
>> particular
>> example it's SOAPAction, however I'm not sure how to do this as you  
>> can
>> only getenv some of the headers.
>
> Erm, it seems neither you nor several who have responded have read  
> TFM.
>
> What header can't you get?
>
> -- 
> Nick Kew

Right bottom posting this time. I've looked in the manual searched on  
the web but I presume there isn't an easy way. I've looked at mod  
header and set env and I don't really want to add a perl wrapper to a  
lovely C program. I was hoping I could do something like getenv 
("HEADERS_REMAINING") or I could write an apache module to grab the  
SOAPAction header and set it in an environment variable. 

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Getting HTTP Headers from CGI program

Posted by Nick Kew <ni...@webthing.com>.
On 31 Dec 2009, at 01:44, Tushar Joshi wrote:

> 
> Hi, 
> 
> I'm trying to get a HTTP header from my CGI program, in this particular
> example it's SOAPAction, however I'm not sure how to do this as you can
> only getenv some of the headers.

Erm, it seems neither you nor several who have responded have read TFM.

What header can't you get?

-- 
Nick Kew

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org