Hi guys,

With all of this CGI talk lately, I cooked something up.
I've been working with a server program based on the ol' mc httpd stack, since I make heavy use of Valentina. However, I've always wanted to break it down into separate cgi scripts. Among other things, that gives me multiple processes more easily.

So my question... is there *any* way to access externals (including the new Mach-o ones with 2.4.3) from a CGI script?

The best I can come up with is running a separate stack which houses the external, and communicating via sockets.

Any ideas?

In case anyone finds this script useful, this is what I'm using to talk to my mc httpd-inspired stack:

#!mc
on startup
  open socket to "127.0.0.1:8080"

  put $REQUEST_METHOD&&$REQUEST_URI&&"CGI"&crLF into theRequest
  if ($HTTP_COOKIE is not empty) then
    put "Cookie: "&$HTTP_COOKIE&crLF after theRequest
  end if
  if ($REMOTE_USER is not empty) then
    put "Remote-User:"&&$REMOTE_USER&crLF after theRequest
  end if

  if ($REQUEST_METHOD = "PUT") then
    read from stdin until empty
    put crLF&it after theRequest
  end if

  write theRequest&crLF&crLF to socket "127.0.0.1:8080"

  read from socket "127.0.0.1:8080" until (crLF&crLF)
  put it into theHeaders
  put lineOffset(theHeaders, "Content-Length:") into theLine
  if (theLine > 0) then
    set the itemDelimiter to ":"
    put item 2 of line theLine of theHeaders into theLength
    read from socket "127.0.0.1:8080" for theLength
    put it into theBody
  else
    read from socket "127.0.0.1:8080" until empty
    put it into theBody
  end if

  ## delete the status line
  delete line 1 of theHeaders
  put (theHeaders&crLF&crLF&theBody)
end startup

Best Regards,
Brian

Reply via email to