From 0820a09923e919d7389c72408a7eeeedcd92991e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 7 Jun 2015 10:02:54 -0400 Subject: [PATCH] lib/curl: fix implementation of `user_agent` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/curl/curl.nit | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/curl/curl.nit b/lib/curl/curl.nit index 8c58646..afb1efa 100644 --- a/lib/curl/curl.nit +++ b/lib/curl/curl.nit @@ -82,10 +82,7 @@ class CurlHTTPRequest var delegate: nullable CurlCallbacks = null is writable # Set the user agent for all following HTTP requests - fun user_agent=(name: String) - do - curl.native.easy_setopt(new CURLOption.user_agent, name) - end + var user_agent: nullable String = null is writable # Execute HTTP request with settings configured through attribute fun execute: CurlResponse @@ -104,6 +101,12 @@ class CurlHTTPRequest err = self.curl.native.easy_setopt(new CURLOption.url, url) if not err.is_ok then return answer_failure(err.to_i, err.to_s) + var user_agent = user_agent + if user_agent != null then + err = curl.native.easy_setopt(new CURLOption.user_agent, user_agent) + if not err.is_ok then return answer_failure(err.to_i, err.to_s) + end + # Callbacks err = self.curl.native.register_callback_header(callback_receiver) if not err.is_ok then return answer_failure(err.to_i, err.to_s) -- 1.7.9.5