Grabbing HTTP Headers

Dave Cragg dcragg at lacscentre.co.uk
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!

Dan

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:


$REQUEST_URI
$REQUEST_METHOD
$SERVER_PROTOCOL
$CONTENT_TYPE
$CONTENT_LENGTH

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

$HTTP_USER_AGENT
$HTTP_HOST

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.
------------------------------------------------------------------

Cheers
Dave



More information about the use-livecode mailing list