Paste: IN: http-part
Author: | kobi |
Mode: | factor |
Date: | Sat, 4 Sep 2010 12:59:48 |
Plain Text |
USING: accessors assocs continuations http http.client
http.client.private io.encodings.binary kernel math.parser
sequences splitting ;
IN: http-part
: <partial-chunk>
[ <get-request> ] 2dip [ number>string ] bi@ "-" glue "bytes=" prepend "Range" set-header ;
: <get-upto-request>
0 swap <partial-chunk> ;
: safer-http-request
[ http-request ] [
nip dup download-failed? [ response>> f ] [ drop f f ] if
] recover "" or ;
: http-safe-get
<get-request> safer-http-request ;
: http-partial-get
<get-upto-request> safer-http-request ;
: http-encoding
0 http-partial-get drop dup [ content-encoding>> ] when ;
: valid-page?
0 http-partial-get nip >boolean ;
: http-binary?
http-encoding binary? ;
: http-size
0 http-partial-get drop
header>> "content-range" swap at
"/" split1-last nip string>number ;
: grab-http-chunk
<partial-chunk> safer-http-request ;
New Annotation