Grabbing HTTP Headers

Dave Cragg dcragg at
Mon May 5 04:04:08 EDT 2003

At 12:13 am -0700 5/5/03, Dan Shafer wrote:
>OK, I give up. I've spent a few hours researching this and haven't
>found an answer.
>Using RR's MetaCard engine as a CGI, how do I grab the HTTP header
>of the incoming request so I can parse it and do meaningful work?
>There has to be a function that does this, but I am stymied trying
>to find it. I have found the libURLLastHTTPHeaders() function but it
>isn't working. Perhaps it's not included in the MetaCard engine and
>therefore not available to CGI processing, but that seems weird
>because CGI is probably 90% of the reason you'd ever want to to get
>an HTTP header!


I just replied on the Metacard list (see below) to your more 
abbreviated question.

All that libUrl stuff has no place in a cgi script (unles you want to 
make a further url request from within your script to another 
server). libUrl is a client-side library only.

This is my reply to your MC list question (for those who don't 
subscribe to both lists):

I don't think there is a way to get all the headers at one time. But 
the headers are exported to environment variables by the http server. 
You can access these directly. I assume this is done according to the 
CGI standard.

For some header data, the names of the environment variables is 
predetermined. For example:


Other environment variables (including custom headers), are formed by 
putting "HTTP_" before the header name (and substituting hyphens with 
underscores). For example:


So if you include the following custom header in your request,

      DansCustomHeader=<some value>

you could retrieve the value of this field in your cgi script by 
getting the $HTTP_DANSCUSTOMHEADER environment variable.


More information about the use-livecode mailing list