From 900e70aa87d071d1141898b8981046d841333311 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 20 Jun 2016 10:44:02 -0400 Subject: [PATCH] app.nit: intro SimpleAsyncHttpRequest MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/app/http_request.nit | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/app/http_request.nit b/lib/app/http_request.nit index 80c6d8b..3fc48c6 100644 --- a/lib/app/http_request.nit +++ b/lib/app/http_request.nit @@ -122,6 +122,23 @@ abstract class AsyncHttpRequest fun after do end end +# Minimal implementation of `AsyncHttpRequest` where `uri` is an attribute +# +# Prints on communication errors and when the server returns an HTTP status code not in the 200s. +# +# ~~~ +# var request = new SimpleAsyncHttpRequest("http://example.com") +# request.start +# ~~~ +class SimpleAsyncHttpRequest + super AsyncHttpRequest + + redef var uri + + redef fun on_load(data, status) do if status < 200 or status >= 299 + then print_error "HTTP request '{uri}' received HTTP status code: {status}" +end + redef class Text # Execute an HTTP GET request synchronously at the URI `self` # -- 1.7.9.5