Execute HTTP request

By default, the response body is returned in an instance of CurlResponse. This behavior can be customized by setting a custom delegate.

Property definitions

curl $ CurlHTTPRequest :: execute
	# Execute HTTP request
	#
	# By default, the response body is returned in an instance of `CurlResponse`.
	# This behavior can be customized by setting a custom `delegate`.
	fun execute: CurlResponse
	do
		# Reset libcurl parameters as the lib is shared and options
		# might affect requests from one another.
		if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized")

		var success_response = new CurlResponseSuccess
		var callback_receiver: CurlCallbacks = success_response
		var err : CURLCode

		# Prepare request
		err = prepare_request(callback_receiver)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		# 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

		return success_response
	end
lib/curl/curl.nit:131,2--157,4

neo4j $ JsonCurlRequest :: execute
	redef fun execute do
		init_headers

		if not self.curl.is_ok then
			return answer_failure(0, "Curl instance is not correctly initialized")
		end

		var success_response = new CurlResponseSuccess
		var callback_receiver: CurlCallbacks = success_response
		if self.delegate != null then callback_receiver = self.delegate.as(not null)

		var err = self.curl.native.easy_setopt(new CURLOption.follow_location, 1)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		err = self.curl.native.easy_setopt(new CURLOption.http_version, 1)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		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)

		err = self.curl.native.register_callback_header(callback_receiver)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		err = self.curl.native.register_callback_body(callback_receiver)
		if not err.is_ok then return answer_failure(err.to_i, err.to_s)

		# HTTP Header
		if self.headers != null then
			var headers_joined = self.headers.join_pairs(": ")
			err = self.curl.native.easy_setopt(
				new CURLOption.httpheader, headers_joined.to_curlslist)
			if not err.is_ok then return answer_failure(err.to_i, err.to_s)
		end

		var err_hook = execute_hook
		if err_hook != null then return err_hook

		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

		return success_response
	end
lib/neo4j/curl_json.nit:45,2--89,4