Paste: decided f is better than empty string

Author: kobi
Mode: factor
Date: Sat, 4 Sep 2010 17:13:44
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> ( url from-bytes to-bytes -- request )
    [ <get-request> ] 2dip [ number>string ] bi@ "-" glue "bytes=" prepend "Range" set-header ;
    
: <get-upto-request> ( url #bytes -- request )
    0 swap <partial-chunk> ;
    
: safer-http-request ( request -- response/f data/f )
    [ http-request ] [
       nip dup download-failed? [ response>> f ] [ drop f f ] if 
    ] recover ;    
    
: http-safe-get ( url -- response/f data/f )
    <get-request> safer-http-request ;
    
: http-partial-get ( url #bytes -- response data/f )
    <get-upto-request> safer-http-request ;

: http-encoding ( url -- encoding/f )
    0 http-partial-get drop dup [ content-encoding>> ] when ;

: valid-page? ( url -- ? )    
    0 http-partial-get nip >boolean ;
    
: http-binary? ( url -- ? )
    http-encoding binary? ;

: http-size ( url -- n )
    0 http-partial-get drop 
    header>> "content-range" swap at
    "/" split1-last nip string>number ;
    
: grab-http-chunk ( url from-bytes to-bytes -- response data )    
    <partial-chunk> safer-http-request ;
    
    

New Annotation

Summary:
Author:
Mode:
Body: