     <get-request> http-request ;
 
 : with-http-get ( url quot -- response )
-    [ <get-request> ] dip with-http-request ; inline
+    [ <get-request> ] dip with-http-request check-response ; inline
 
 : <delete-request> ( url -- request )
     <client-request> "DELETE" >>method ;

    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 )


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

ERROR: download-failed response data ;

M: download-failed error.
    "HTTP request failed:" print nl
    [ response>> . ] [ data>> . ] bi ;

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

: check-response ( response -- response )
    f check-response* drop ;

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

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