lib/curl: allow raw body string in CurlHTTPRequest
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 20 Sep 2017 21:43:05 +0000 (17:43 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 12 Oct 2017 00:49:00 +0000 (20:49 -0400)
So we can send something else than POST formatted data.

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/curl/curl.nit

index 6ae0b9a..0e49515 100644 (file)
@@ -100,6 +100,13 @@ class CurlHTTPRequest
        # Data for the body of a POST request
        var data: nullable HeaderMap is writable
 
+       # Raw body string
+       #
+       # Set this value to send raw data instead of the POST formatted `data`.
+       #
+       # If `data` is set, the body will not be sent.
+       var body: nullable String is writable
+
        # Header content of the request
        var headers: nullable HeaderMap is writable
 
@@ -156,6 +163,9 @@ class CurlHTTPRequest
                        var postdatas = data.to_url_encoded(self.curl)
                        err = self.curl.native.easy_setopt(new CURLOption.postfields, postdatas)
                        if not err.is_ok then return answer_failure(err.to_i, err.to_s)
+               else if body != null then
+                       err = self.curl.native.easy_setopt(new CURLOption.postfields, body.as(not null))
+                       if not err.is_ok then return answer_failure(err.to_i, err.to_s)
                end
 
                var err_resp = perform