From 6a2d6971c6e0c4ece0a67473ab9fe87460e94599 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sat, 12 Oct 2013 10:57:00 -0700 Subject: [PATCH] http.client: adding http-request*. --- basis/http/client/client-docs.factor | 6 ++++++ basis/http/client/client.factor | 3 +++ 2 files changed, 9 insertions(+) diff --git a/basis/http/client/client-docs.factor b/basis/http/client/client-docs.factor index b579154929..bfc63fa3b0 100644 --- a/basis/http/client/client-docs.factor +++ b/basis/http/client/client-docs.factor @@ -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 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 diff --git a/basis/http/client/client.factor b/basis/http/client/client.factor index 4bac064112..5d5e121f0a 100644 --- a/basis/http/client/client.factor +++ b/basis/http/client/client.factor @@ -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 ; + : ( url -- request ) "GET" ;