[REBOL] CGI: reading POST-method data with read-io
From: alex::pini::mclink::it at: 24-Aug-2000 0:52
>- Open Your Mind -<
(Mr. Sassenrath should receive a CC of this message as a comment on the Network Protocols
chapter, Second Revision, Draft 1)
I've read the User's Guide, the old FAQs, the how-to and the recent Networking chapter,
but I still lack insight on the inner workings of read-io. I can make conjectures, they
may even work, but I don't like that: in the long run, I could accumulate all sorts of
---------- Buffer ----------
We need a buffer. If we need to read 2000 bytes, the buffer is made 2002 bytes long with
data1: make string! 2002
I guess the extra 2 bytes are needed to store ancillary information, but their content
is not my concern, for now.
Can we make the buffer as in
data2: make string! 2000
data3: copy ""
since strings can (usually?) be extended as needed?
Will read-io work with a buffer like data3?
Is data1 initialized like that for better performance only or is it *required* by the
---------- Correct buffer-length ----------
According to CGI quasi-official specs, once I've checked the message body is in URL-encoded
format, I must read no more than CONTENT_LENGTH bytes from system/ports/input.
So if I want to go elegant and read *exactly* CONTENT_LENGTH bytes I make my buffer exactly
2 bytes longer than that and use read-io to read exactly CONTENT_LENGTH bytes, so I don't
waste memory in a prudent 128 MB buffer, right?
---------- Data readiness ----------
It has been pointed out (but I can't remember where) that the message body could possibly
be transported very slowly to the CGI script, due to heavy traffic on the net, so it
is possible that the message body is not *fully* there when read-io is issued. On the
other hand, the length you ask read-io is a *maximum* length. IIRC, Jan posted a reading
cycle on the list to take care of this (will look for it as soon as I can).
If CONTENT_LENGTH is, say, 22000 bytes, what happens if I request my 22000 bytes but
only 1000 are available? Will read-io return the 1000 bytes immediately (which means
I have to do the reading cycle) or will it wait until the whole 22000 bytes are transported
and return them all? What about timeouts?
---------- In the end ----------
Will read-io be fully described somewhere? ((-:
Alessandro Pini ([alex--pini--mclink--it])
Now I'm mumblin' and I'm screamin' / And I don't know what I'm singin'
(Weird Al Yankovic)