Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: POST examples ...

From: gjones05:mail:orion at: 4-Jun-2001 13:06

From "Scott Jones" .. SJ> > insert http-port http-request SJ> > ;now grabbing header stuff 1 byte at a time SJ> > ;so that we can get content length SJ> > ;look for two newlines in a row SJ> > data: make string! 1000 SJ> > while [not parse/all data [to "^/^/" to end]][ SJ> > append data copy/part http-port 1 SJ> > ] From: "Petr Krenzelok"
> .. pressed for the time. I can understand most parts of the script,
but are
> above lines correct? So you run 'while loop containing 'parse. What do
you
> do if string like "asdfasf^/^/ something else" arrives to your port?
Are
> you sure that by reading out 1 byte from the port you will get whole
string
> till ^/^/ is reached?
The logic I used was based on the fact that the header info is separated from the content by (a minimum of) 2 CRLFs (by http specification as I recall). What my hacked example does not take into account are error conditions, which could well occur. I guess the loop could check for excessive content header length (meaning it missed the two newline characters for what ever reason). It's hard to imagine a header being longer than a few hundred bytes, so I guess it could check to be sure the length doesn't exceed some reasonable default. I just realized that the "^/^/" could represent different things on different platforms, but the specification uses the CRLFCRLF sequence as the separator of header from content. I only let it read one byte at a time so as to not overshoot the sequence. I guess one could just read an arbitrary length the first time through, parse this data for header, then let the rest (the first part of the content) be parsed off to the content.
> Thanks anyway - will try it at my work tomorrow ... > > > Hope this one helps *and* solve the problem. > > I already solved it :-) Well, the only one problem is 'read needs lots
of
> memory, but it works :-) Right now I just want to get more familiar
with
> POST method, so I am asking questions you are answering in a great
manner.
> Appreciated!
I am sorry that I misunderstood that you *had* already solved it. I thought the code you posted showed the nice way that you constructed the parameters for a POST operation. I thought you were still wishing for a way to know the length and download either in portions and/or download only a specific portion. I used Martin J's code and method, mainly for speed, because all I had to do was change the parts that managed the port and getting header/length stuff. I posted this most recent code as a way of showing how to manage the port. I meant no slight to you, of course. Sorry. The way I outlined should avoid any significant memory problems, but performance could be improved for large files by picking a larger length. The size of the minimal hard disk storage unit would be the minimal ideal (is it a sector or a cluster; I have forgotten). Best wishes, --Scott Jones