Nicolas Cueto wrote:
> 
> Hi,
> 
> As suggested (thank you Andu and Phil Davis), (1) I'm checking
> the HTTP protocol (ok, I'm seeing somewhat how it works, but
> how do I translate that into MC language?), and (2) posted on
> Google's Unix-server newsgroup (replies there: either the MC
> method is broken, an "out of scope" error in my loop test (?),
> and that there is "no eof" for the POST data stream), _BUT_
> I'd like to keep plugging away at it here. Sorry!

There's nothing broken with MC. You first read the header, look for
"Content-Length:" line and then read for that amount. I'll give you a
simplistic example bellow but test it since I just make it up. It reads
as much as it comes through the pipe at a time in a repeat. 

#!mc

local tVar,tReply,tRead

   on startup
 if $REQUEST_METHOD is "POST" then
 read from stdin with message "readData" 
repeat while tVar is empty
wait for messages
end repeat 
put "Content-Type: text/html" &crlf&\
"Content-Length:"&& the length of tReply &\ #this is your minimal header
crlf&crlf & tReply into cgiReply
put cgiReply
end startup

on readData x,y
put y after tRead
put lineOffset(crlf&crlf,tRead) into tEnd #end of header
if tEnd is not 0 then #got the header and more
put lineOffset("Content Length:",tRead) into tLine
put word 2 of line tLine of tRead into tLength
deleate line 1 to tEnd in tRead #get rid of the header
if length(tRead)=tLength then #we got the whole body
#process the request
#process the reply, put it into tReply
put true into tVar #return to first handler
else #didn't get the whole body
read from socket x with message "readMore"
end if
else #didn't get the whole header
read from socket x with message "readData" 
end if
end readData

on readMore x,y
put y after tRead
if length(tRead)=tLength then
#process the request
#process the reply, put it into tReply
put true into tVar #return to first handler
else #didn't get the whole body
read from socket x with message "readMore"
end if
end readMore

> Thank you.
> 
> Nicolas R Cueto

Andu

Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to