+ # Perform request
+ var err_resp = perform
+ if err_resp != null then return err_resp
+
+ var st_code = self.curl.native.easy_getinfo_long(new CURLInfoLong.response_code)
+ if not st_code == null then success_response.status_code = st_code
+
+ self.curl.native.easy_clean
+
+ return success_response
+ end
+
+ # Internal function that sets cURL options and request' parameters
+ private fun prepare_request(callback_receiver: CurlCallbacks) : CURLCode
+ do
+ var err
+
+ # cURL options and delegates
+ err = set_curl_options
+ if not err.is_ok then return err
+
+ # Callbacks
+ err = set_curl_callback(callback_receiver)
+ if not err.is_ok then return err
+
+ # HTTP Header
+ err = set_curl_http_header
+ if not err.is_ok then return err
+
+ # Set HTTP method and body
+ err = set_method
+ if not err.is_ok then return err
+ err = set_body
+
+ return err
+ end
+
+ # Set cURL parameters according to assigned HTTP method set in method
+ # attribute and body if the method allows it according to RFC7231
+ private fun set_method : CURLCode
+ do
+ var err : CURLCode
+
+ if self.method=="GET" then
+ err=self.curl.native.easy_setopt(new CURLOption.get, 1)
+
+ else if self.method=="POST" then
+ err=self.curl.native.easy_setopt(new CURLOption.post, 1)
+
+ else if self.method=="HEAD" then
+ err=self.curl.native.easy_setopt(new CURLOption.no_body,1)
+
+ else
+ err=self.curl.native.easy_setopt(new CURLOption.custom_request,self.method)
+ end
+ return err
+ end
+
+ # Set request's body
+ private fun set_body : CURLCode
+ do
+ var err
+ var data = self.data
+ var body = self.body
+
+ if data != null then
+ 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 err
+ else if body != null then
+ err = self.curl.native.easy_setopt(new CURLOption.postfields, body)
+ if not err.is_ok then return err
+ end
+ return new CURLCode.ok
+ end
+
+ # Set cURL options
+ # such as delegate, follow location, URL, user agent and address family
+ private fun set_curl_options : CURLCode
+ do