     request get url>> url-addr ascii <client> drop
     1 minutes over set-timeout ;
 
-: (with-http-request) ( request quot: ( chunk -- ) -- response )
+: with-http-request ( request quot: ( chunk -- ) -- response )
     swap
     request [
         <request-socket> [


: success? ( code -- ? ) 200 299 between? ;

ERROR: download-failed response ;

M: download-failed error.
    "HTTP request failed:" print nl
    response>> . ;

: check-response ( response -- response )
    dup code>> success? [ download-failed ] unless ;

: with-http-request ( request quot -- response )
    (with-http-request) check-response ; inline

: http-request ( request -- response data )
    [ [ % ] with-http-request ] B{ } make
    over content-charset>> decode ;

: <client-request> ( url -- request )
    <request> swap >url ensure-port >>url ;

    redirects get max-redirects < [
        request get clone
        swap "location" header redirect-url
        "GET" >>method swap with-http-request
    ] [ too-many-redirects ] if ; inline recursive

: read-chunk-size ( -- n )
