http.client: adding http-request*.

db4
John Benediktsson 2013-10-12 10:57:00 -07:00
parent eb801f1072
commit 6a2d6971c6
2 changed files with 9 additions and 0 deletions

View File

@ -135,6 +135,11 @@ HELP: http-request
{ $description "Sends an HTTP request to an HTTP server, and reads the response." }
{ $errors "Throws an error if the HTTP request fails." } ;
HELP: http-request*
{ $values { "request" request } { "data" sequence } }
{ $description "A variant of " { $link http-request } " that checks that the response was successful." }
{ $errors "Throws an error if the HTTP request fails or is not successful." } ;
HELP: with-http-request
{ $values { "request" request } { "quot" { $quotation "( chunk -- )" } } { "response" response } }
{ $description "Sends an HTTP request to an HTTP server, and reads the response incrementally. Chunks of data are passed to the quotation as they are read. Does not throw an error if the HTTP request fails; to do so, call " { $link check-response } " on the " { $snippet "response" } "." } ;
@ -151,6 +156,7 @@ ARTICLE: "http.client.get" "GET requests with the HTTP client"
{ $subsections
<get-request>
http-request
http-request*
}
"The " { $link http-get } " and " { $link http-request } " words output sequences. This is undesirable if the response data may be large. Another pair of words take a quotation instead, and pass the quotation chunks of data incrementally:"
{ $subsections

View File

@ -170,6 +170,9 @@ ERROR: download-failed response ;
[ [ % ] with-http-request ] B{ } make
over content-encoding>> decode check-response-with-body ;
: http-request* ( request -- data )
http-request swap check-response drop ;
: <get-request> ( url -- request )
"GET" <client-request> ;