Grabbing HTTP Header

LiangTyan Fui mlist at afteroffice.com
Mon May 5 21:29:01 EDT 2003


On 5/5/03 11:49 PM, "Dan Shafer" <dan at eclecticity.com> wrote:

>> At 6:23 pm -0700 4/5/03, Dan Shafer wrote:
>>> OK, I give up. What's the function/method/magic incantation to grab
>>> the incoming HTTP header in the MC CGI?
>>> 
>>> I know what to do with this info once I have it but I'm darned if I
>>> can find any reference to anything resembling HTTP headers.
>> 
> Dave Cragg answered in part:
> 
>> 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.
> 
> There *is* a function in libURL called "libURLLastHTTPHeaders()" that at least
> *sounded* like it would do what I want. I saw a reference somewhere to
> grabbing the headers and then doing a line-parse on them.
> 
> But that function doesn't seem to work in the mc CGI engine. At least I'm
> speculating that's the problem. Here's my simple-dimple script:
> 
> #!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
> 
> I figured I'd just spit the header back and at least confirm this was working.
> But I get the ubiquitous and completely unhelpful "server configuration"
> error. My current theory is that libURL isn't included in the MC engine (which
> would make no sense to me but if it's reality, I'll deal with it).
> 
> So now I'll be off trying to figure out how to communicate directly with the
> environment and hunt down these environment variables from inside the CGI
> engine. This is fun; I hope it also turns out to be rewarding!

I though the echo.mt cgi has it?

#!/home/mc/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
  
  put "" into tContainer
  if $CONTENT_LENGTH > 0 then
    put $CONTENT_LENGTH into tLen
    put "" into tContainer
    put 0 into tContainerSize
    repeat
      read from stdin until empty
      put it after tContainer
      add length(it) to tContainerSize
      if tContainerSize >= tLen then
        exit repeat
      end if
    end repeat
  end if
  
  #!
  put "Content-Type: text/plain" & cr
  put "Content-Length:" && the length of (buffer & tContainer) & cr & cr
  put buffer & tContainer
end startup

-- 





More information about the metacard mailing list