Grabbing HTTP Headers

Monte Goulding monte at sweattechnologies.com
Mon May 5 03:42:01 EDT 2003


> 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!
>
> Here's my script, set up to run on the MC CGI engine. I know the engine
> works. It's just this script that gives me the usual server
> configuration error garbage.
>
> #!mc
> on startUp
>    put libURLLastHTTPHeaders() into tResponse
>    put "Content-Type: text/html" & crlf
>    put "Content-Length:" & (the length of tResponse) & crlf & crlf
>    put tResponse
> end startUp
>
> Help!

Hi Dan

libURL isn't part of the engine. It's just a library stack (in Rev it's a
back script). Get your version of MC and do the following:
clone stack "libURL"
set the name of it to "myLibURL"
save stack "myLibURL" as "myLibURL.mc"

then put it next to your CGI file

Then change your CGI script to read:

#!mc
on startUp
   library "mylibURL"
   put libURLLastHTTPHeaders() into tResponse
   put "Content-Type: text/html" & crlf
   put "Content-Length:" & (the length of tResponse) & crlf & crlf
   put tResponse
end startUp

However having said that libURL isn't designed for what you think it is.
It's  used for the url put, get, load, delete etc commands not for CGI. I
have no idea what you will get from the above but probably not much.

The following is a copy of the old echo.cgi script I cut my teeth on:

#!mc
# This MetaTalk script loops over all the environment variables
# set by the server when it runs a CGI application printing out
# its name and value.
on startup
# loop over all of the global variables, getting name and value
  repeat for each item i in the globals
   put i && "=" && value(i)& return after buffer
  end repeat
# write minimal set of HTTP headers to stdout
  read from stdin until empty
  put it after buffer
  replace cr with "<P>" in buffer
  put "Content-Type: text/plain" & cr
  put "Content-Length:" && the length of buffer & cr & cr
  put buffer
 end startup

Hope this helps

Monte




More information about the use-livecode mailing list