Execute an HTTP GET request synchronously at the URI self

var response = "http://example.org/".http_get
if response.is_error then
    print_error response.error
else
    print "HTTP status code: {response.code}"
    print response.value
end

Property definitions

app :: http_request $ Text :: http_get
	# Execute an HTTP GET request synchronously at the URI `self`
	#
	# ~~~nitish
	# var response = "http://example.org/".http_get
	# if response.is_error then
	#     print_error response.error
	# else
	#     print "HTTP status code: {response.code}"
	#     print response.value
	# end
	# ~~~
	private fun http_get: HttpRequestResult is abstract
lib/app/http_request.nit:165,2--176,52

linux :: http_request $ Text :: http_get
	redef fun http_get
	do
		var req = new CurlHTTPRequest(to_s)
		var rep = req.execute
		if rep isa CurlResponseSuccess then
			return new HttpRequestResult(rep.body_str, null, rep.status_code)
		else
			assert rep isa CurlResponseFailed
			var error = new IOError(rep.error_msg)
			return new HttpRequestResult(null, error)
		end
	end
lib/linux/http_request.nit:27,2--38,4

ios :: http_request $ Text :: http_get
	redef fun http_get
	do
		var error_ref = new Ref[NSString]("Unknown Error".to_nsstring)
		var data = to_nsstring.native_http_get(60.0, error_ref)

		if data.address_is_null then
			# There was an error
			var error = new IOError(error_ref.item.to_s)
			return new HttpRequestResult(null, error)
		else
			# TODO use the real return code instead of 200
			return new HttpRequestResult(data.to_s, null, 200)
		end
	end
lib/ios/http_request.nit:33,2--46,4

android :: http_request $ Text :: http_get
	redef fun http_get
	do
		jni_env.push_local_frame 8
		var juri = self.to_java_string
		var jrep = java_http_get(juri)

		assert not jrep.is_java_null

		var res
		if jrep.is_exception then
			jrep = jrep.as_exception

			# If the top exception doesn't have a message, get it from its causes.
			var msg = null
			var cause: JavaThrowable = jrep
			loop
				var jmsg = cause.message
				if not jmsg.is_java_null then
					msg = jmsg.to_s
					break
				else
					cause = cause.cause
					if cause.is_java_null then break
				end
			end
			if msg == null then msg = jrep.to_s

			res = new HttpRequestResult(null, new IOError(msg))
		else if jrep.is_http_response then
			jrep = jrep.as_http_response
			res = new HttpRequestResult(jrep.content.to_s, null, jrep.status_code)
		else abort

		jni_env.pop_local_frame
		return res
	end
lib/android/http_request.nit:46,2--81,4