lib/curl: fix implementation of `user_agent`
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 7 Jun 2015 14:02:54 +0000 (10:02 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sun, 7 Jun 2015 19:41:46 +0000 (15:41 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/curl/curl.nit

index 8c58646..afb1efa 100644 (file)
@@ -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)