/* web.c generated by valac 0.56.19, the Vala compiler
 * generated from web.vala, do not modify */

#include "protonplus_core.h"
#include <glib.h>
#include <libsoup/soup.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>
#include "config.h"
#include <gobject/gvaluecollector.h>

#define PROTON_PLUS_UTILS_WEB_PROXY_MODE_SYSTEM 0
#define PROTON_PLUS_UTILS_WEB_PROXY_MODE_MANUAL 1
#define PROTON_PLUS_UTILS_WEB_MAX_DOWNLOAD_ATTEMPTS 2
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _ProtonPlusUtilsWebGetRequestData ProtonPlusUtilsWebGetRequestData;
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ProtonPlusUtilsWebSendRequestData ProtonPlusUtilsWebSendRequestData;
typedef struct _ProtonPlusUtilsWebCleanupPartialDownloadData ProtonPlusUtilsWebCleanupPartialDownloadData;
typedef struct _ProtonPlusUtilsWebDownloadOnceData ProtonPlusUtilsWebDownloadOnceData;
typedef struct _ProtonPlusUtilsWebDownloadData ProtonPlusUtilsWebDownloadData;
enum  {
	PROTON_PLUS_UTILS_WEB_RESPONSE_0_PROPERTY,
	PROTON_PLUS_UTILS_WEB_RESPONSE_CODE_PROPERTY,
	PROTON_PLUS_UTILS_WEB_RESPONSE_STATUS_CODE_PROPERTY,
	PROTON_PLUS_UTILS_WEB_RESPONSE_BODY_PROPERTY,
	PROTON_PLUS_UTILS_WEB_RESPONSE_ERROR_MESSAGE_PROPERTY,
	PROTON_PLUS_UTILS_WEB_RESPONSE_IS_SUCCESSFUL_PROPERTY,
	PROTON_PLUS_UTILS_WEB_RESPONSE_NUM_PROPERTIES
};
static GParamSpec* proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_NUM_PROPERTIES];
typedef struct _ProtonPlusUtilsParamSpecWeb ProtonPlusUtilsParamSpecWeb;

struct _ProtonPlusUtilsWebGetRequestData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* uri;
	ProtonPlusUtilsWebGetRequestType get_request_type;
	GCancellable* cancellable;
	ProtonPlusUtilsWebResponse* result;
	SoupMessage* message;
	SoupMessage* _tmp0_;
	GSettings* _tmp1_;
	gboolean _tmp2_;
	gchar* key;
	GSettings* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	SoupMessage* _tmp8_;
	SoupMessageHeaders* _tmp9_;
	SoupMessageHeaders* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _vala1_key;
	GSettings* _tmp14_;
	gchar* _tmp15_;
	const gchar* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	SoupMessage* _tmp19_;
	SoupMessageHeaders* _tmp20_;
	SoupMessageHeaders* _tmp21_;
	const gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	SoupMessage* _tmp25_;
	SoupMessageHeaders* _tmp26_;
	SoupMessageHeaders* _tmp27_;
	SoupMessage* _tmp28_;
	SoupMessageHeaders* _tmp29_;
	SoupMessageHeaders* _tmp30_;
	ProtonPlusUtilsWebResponse* response;
	SoupMessage* _tmp31_;
	ProtonPlusUtilsWebResponse* _tmp32_;
	ProtonPlusUtilsWebResponse* _tmp33_;
	ProtonPlusUtilsWebResponse* _tmp34_;
	ProtonPlusUtilsWebResponse* _tmp35_;
	gboolean _tmp36_;
	gboolean _tmp37_;
	ProtonPlusUtilsWebResponse* _tmp38_;
	ProtonPlusUtilsWebResponse* _tmp39_;
	gboolean _tmp40_;
	ProtonPlusUtilsWebResponse* _tmp41_;
	gint _tmp42_;
	gint _tmp43_;
	ProtonPlusUtilsWebResponse* _tmp44_;
	gint _tmp45_;
	gint _tmp46_;
	ProtonPlusUtilsWebResponse* _tmp47_;
	gboolean _tmp48_;
	ProtonPlusUtilsWebResponse* _tmp49_;
	gint _tmp50_;
	gint _tmp51_;
	gboolean _tmp52_;
	gboolean _tmp53_;
	gboolean _tmp54_;
	ProtonPlusUtilsWebResponse* _tmp55_;
	ProtonPlusUtilsWebResponse* _tmp56_;
	ProtonPlusUtilsWebResponse* _tmp57_;
};

struct _ProtonPlusUtilsWebSendRequestData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	SoupMessage* message;
	GCancellable* cancellable;
	ProtonPlusUtilsWebResponse* result;
	ProtonPlusUtilsWebResponse* response;
	ProtonPlusUtilsWebResponse* _tmp0_;
	GBytes* bytes;
	SoupSession* _tmp1_;
	SoupSession* _tmp2_;
	GBytes* _tmp3_;
	ProtonPlusUtilsWebResponse* _tmp4_;
	guint _tmp5_;
	guint _tmp6_;
	ProtonPlusUtilsWebResponse* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	ProtonPlusUtilsWebResponse* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	ProtonPlusUtilsWebResponse* _tmp13_;
	GBytes* _tmp14_;
	gsize _tmp15_;
	guint8* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	ProtonPlusUtilsWebResponse* _tmp19_;
	GError* e;
	gboolean _tmp20_;
	GError* _tmp21_;
	GError* _tmp22_;
	ProtonPlusUtilsWebResponse* _tmp23_;
	gboolean _tmp24_;
	GError* _tmp25_;
	GError* _tmp26_;
	ProtonPlusUtilsWebResponse* _tmp27_;
	GError* _tmp28_;
	ProtonPlusUtilsWebResponse* _tmp29_;
	GError* _tmp30_;
	ProtonPlusUtilsWebResponse* _tmp31_;
	GError* _tmp32_;
	GError* _tmp33_;
	const gchar* _tmp34_;
	ProtonPlusUtilsWebResponse* _tmp35_;
	GError* _tmp36_;
	const gchar* _tmp37_;
	GError* _inner_error0_;
};

struct _ProtonPlusUtilsWebCleanupPartialDownloadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GFile* file;
	GFileOutputStream* output_stream;
	GError* e;
	GError* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _vala1_e;
	GError* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GError* _inner_error0_;
};

struct _ProtonPlusUtilsWebDownloadOnceData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* url;
	GFile* file;
	GCancellable* cancellable;
	ProtonPlusUtilsWebprogress_callback progress_callback;
	gpointer progress_callback_target;
	gchar* error_message;
	gboolean result;
	GFileOutputStream* output_stream;
	gboolean has_partial_file;
	SoupMessage* soup_message;
	SoupMessage* _tmp0_;
	GInputStream* input_stream;
	SoupSession* _tmp1_;
	SoupSession* _tmp2_;
	SoupMessage* _tmp3_;
	GInputStream* _tmp4_;
	SoupMessage* _tmp5_;
	guint _tmp6_;
	guint _tmp7_;
	SoupMessage* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	SoupMessage* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	GFileOutputStream* _tmp15_;
	GFileOutputStream* _tmp16_;
	GFileOutputStream* _tmp17_;
	gint64 server_download_size;
	SoupMessage* _tmp18_;
	SoupMessageHeaders* _tmp19_;
	gboolean is_percent;
	gint64 bytes_downloaded;
	gdouble _tmp20_;
	gboolean is_canceled;
	gint64 start_time;
	gint64 last_progress_report_time;
	gboolean _tmp21_;
	ProtonPlusUtilsDownloadManager* download_manager;
	ProtonPlusUtilsDownloadManager* _tmp22_;
	ProtonPlusUtilsDownloadManager* _tmp23_;
	ProtonPlusUtilsDownloadManager* _tmp24_;
	gint64 speed_limit_bps_before_read;
	ProtonPlusUtilsDownloadManager* _tmp25_;
	gint64 _tmp26_;
	gint64 _tmp27_;
	guint64 throttle_generation_before_read;
	ProtonPlusUtilsDownloadManager* _tmp28_;
	guint64 _tmp29_;
	guint64 _tmp30_;
	gsize chunk_size;
	gint64 suggested_chunk;
	gint64 transfer_started_us;
	GBytes* chunk;
	GInputStream* _tmp31_;
	GBytes* _tmp32_;
	GBytes* _tmp33_;
	gsize bytes_written;
	GFileOutputStream* _tmp34_;
	GBytes* _tmp35_;
	gsize _tmp36_;
	guint8* _tmp37_;
	gsize _tmp38_;
	ProtonPlusUtilsDownloadManager* _tmp39_;
	gboolean _tmp40_;
	gint64 now;
	gboolean _tmp41_;
	gboolean _tmp42_;
	GFileOutputStream* _tmp43_;
	GFileOutputStream* _tmp44_;
	GError* e;
	GFileOutputStream* _tmp45_;
	GError* _tmp46_;
	GError* _tmp47_;
	GError* _inner_error0_;
};

struct _ProtonPlusUtilsWebDownloadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* url;
	gchar* path;
	GCancellable* cancellable;
	ProtonPlusUtilsWebprogress_callback progress_callback;
	gpointer progress_callback_target;
	gchar* error_message;
	gboolean result;
	GFile* file;
	GFile* _tmp0_;
	gint attempt;
	gboolean _tmp1_;
	gint _tmp2_;
	gboolean _tmp3_;
	GFile* _tmp4_;
	gchar* _tmp5_;
	gboolean _tmp6_;
	GError* e;
	gboolean _tmp7_;
	GError* _tmp8_;
	GError* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GError* _tmp13_;
	const gchar* _tmp14_;
	GError* _tmp15_;
	gchar* _tmp16_;
	GError* _inner_error0_;
};

struct _ProtonPlusUtilsWebResponsePrivate {
	ProtonPlusReturnCode _code;
	gint _status_code;
	gchar* _body;
	gchar* _error_message;
};

struct _ProtonPlusUtilsParamSpecWeb {
	GParamSpec parent_instance;
};

static gpointer proton_plus_utils_web_parent_class = NULL;
static SoupSession* proton_plus_utils_web__session;
static SoupSession* proton_plus_utils_web__session = NULL;
static gint proton_plus_utils_web_applied_proxy_mode;
static gint proton_plus_utils_web_applied_proxy_mode = -1;
static gchar* proton_plus_utils_web_applied_proxy_url;
static gchar* proton_plus_utils_web_applied_proxy_url = NULL;
static gint ProtonPlusUtilsWebResponse_private_offset;
static gpointer proton_plus_utils_web_response_parent_class = NULL;

static SoupSession* proton_plus_utils_web_get_current_session (void);
static gboolean proton_plus_utils_web_is_valid_proxy_url (const gchar* proxy_url);
static void proton_plus_utils_web_get_request_data_free (gpointer _data);
static gboolean proton_plus_utils_web_get_request_co (ProtonPlusUtilsWebGetRequestData* _data_);
static void proton_plus_utils_web_send_request (SoupMessage* message,
                                         GCancellable* cancellable,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
static ProtonPlusUtilsWebResponse* proton_plus_utils_web_send_request_finish (GAsyncResult* _res_);
static void proton_plus_utils_web_get_request_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void proton_plus_utils_web_send_request_data_free (gpointer _data);
static gboolean proton_plus_utils_web_send_request_co (ProtonPlusUtilsWebSendRequestData* _data_);
static void proton_plus_utils_web_send_request_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void proton_plus_utils_web_report_download_progress (ProtonPlusUtilsWebprogress_callback progress_callback,
                                                     gpointer progress_callback_target,
                                                     gboolean is_percent,
                                                     gint64 bytes_downloaded,
                                                     gint64 server_download_size,
                                                     gint64 start_time);
static gdouble* _double_dup (gdouble* self);
static void proton_plus_utils_web_cleanup_partial_download_data_free (gpointer _data);
static void proton_plus_utils_web_cleanup_partial_download (GFile* file,
                                                     GFileOutputStream* output_stream,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
static void proton_plus_utils_web_cleanup_partial_download_finish (GAsyncResult* _res_);
static gboolean proton_plus_utils_web_cleanup_partial_download_co (ProtonPlusUtilsWebCleanupPartialDownloadData* _data_);
static void proton_plus_utils_web_cleanup_partial_download_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static gboolean proton_plus_utils_web_should_retry_download_error (GError* _error_,
                                                            gint attempt);
static gchar* proton_plus_utils_web_get_download_error_message (GError* _error_);
static void proton_plus_utils_web_download_once_data_free (gpointer _data);
static void proton_plus_utils_web_download_once (const gchar* url,
                                          GFile* file,
                                          GCancellable* cancellable,
                                          ProtonPlusUtilsWebprogress_callback progress_callback,
                                          gpointer progress_callback_target,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
static gboolean proton_plus_utils_web_download_once_finish (GAsyncResult* _res_,
                                                     gchar** error_message,
                                                     GError** error);
static gboolean proton_plus_utils_web_download_once_co (ProtonPlusUtilsWebDownloadOnceData* _data_);
static void proton_plus_utils_web_download_once_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_);
static void proton_plus_utils_web_download_data_free (gpointer _data);
static gboolean proton_plus_utils_web_download_co (ProtonPlusUtilsWebDownloadData* _data_);
static void proton_plus_utils_web_download_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static void proton_plus_utils_web_response_finalize (GObject * obj);
static GType proton_plus_utils_web_response_get_type_once (void);
static void _vala_proton_plus_utils_web_response_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec);
static void _vala_proton_plus_utils_web_response_set_property (GObject * object,
                                                        guint property_id,
                                                        const GValue * value,
                                                        GParamSpec * pspec);
static void proton_plus_utils_web_finalize (ProtonPlusUtilsWeb * obj);
static GType proton_plus_utils_web_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static GType
proton_plus_utils_web_get_request_type_get_type_once (void)
{
	static const GEnumValue values[] = {{PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_OTHER, "PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_OTHER", "other"}, {PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITHUB, "PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITHUB", "github"}, {PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITLAB, "PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITLAB", "gitlab"}, {PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_FORGEJO, "PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_FORGEJO", "forgejo"}, {PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_STEAMTINKERLAUNCH, "PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_STEAMTINKERLAUNCH", "steamtinkerlaunch"}, {0, NULL, NULL}};
	GType proton_plus_utils_web_get_request_type_type_id;
	proton_plus_utils_web_get_request_type_type_id = g_enum_register_static ("ProtonPlusUtilsWebGetRequestType", values);
	return proton_plus_utils_web_get_request_type_type_id;
}

GType
proton_plus_utils_web_get_request_type_get_type (void)
{
	static volatile gsize proton_plus_utils_web_get_request_type_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_web_get_request_type_type_id__once)) {
		GType proton_plus_utils_web_get_request_type_type_id;
		proton_plus_utils_web_get_request_type_type_id = proton_plus_utils_web_get_request_type_get_type_once ();
		g_once_init_leave (&proton_plus_utils_web_get_request_type_type_id__once, proton_plus_utils_web_get_request_type_type_id);
	}
	return proton_plus_utils_web_get_request_type_type_id__once;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

SoupSession*
proton_plus_utils_web_get_session (void)
{
	SoupSession* _tmp0_;
	SoupSession* _tmp1_;
	SoupSession* _tmp2_;
	SoupSession* result;
	_tmp0_ = proton_plus_utils_web_get_current_session ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

void
proton_plus_utils_web_update_proxy_settings (void)
{
	SoupSession* _tmp0_;
	gint proxy_mode = 0;
	gchar* proxy_url = NULL;
	gchar* _tmp1_;
	GSettings* _tmp2_;
	gboolean _tmp8_ = FALSE;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	_tmp0_ = proton_plus_utils_web__session;
	if (_tmp0_ == NULL) {
		return;
	}
	proxy_mode = PROTON_PLUS_UTILS_WEB_PROXY_MODE_SYSTEM;
	_tmp1_ = g_strdup ("");
	proxy_url = _tmp1_;
	_tmp2_ = proton_plus_globals_SETTINGS;
	if (_tmp2_ != NULL) {
		GSettings* _tmp3_;
		GSettings* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp3_ = proton_plus_globals_SETTINGS;
		proxy_mode = g_settings_get_enum (_tmp3_, "proxy-mode");
		_tmp4_ = proton_plus_globals_SETTINGS;
		_tmp5_ = g_settings_get_string (_tmp4_, "proxy-url");
		_tmp6_ = _tmp5_;
		_tmp7_ = string_strip (_tmp6_);
		_g_free0 (proxy_url);
		proxy_url = _tmp7_;
		_g_free0 (_tmp6_);
	}
	if (proton_plus_utils_web_applied_proxy_mode == proxy_mode) {
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		_tmp9_ = proton_plus_utils_web_applied_proxy_url;
		_tmp10_ = proxy_url;
		_tmp8_ = g_strcmp0 (_tmp9_, _tmp10_) == 0;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		_g_free0 (proxy_url);
		return;
	}
	if (proxy_mode == PROTON_PLUS_UTILS_WEB_PROXY_MODE_MANUAL) {
		const gchar* _tmp11_;
		_tmp11_ = proxy_url;
		if (proton_plus_utils_web_is_valid_proxy_url (_tmp11_)) {
			SoupSession* _tmp12_;
			const gchar* _tmp13_;
			GSimpleProxyResolver* _tmp14_;
			GSimpleProxyResolver* _tmp15_;
			_tmp12_ = proton_plus_utils_web__session;
			_tmp13_ = proxy_url;
			_tmp14_ = (GSimpleProxyResolver*) g_simple_proxy_resolver_new (_tmp13_, NULL);
			_tmp15_ = _tmp14_;
			soup_session_set_proxy_resolver (_tmp12_, (GProxyResolver*) _tmp15_);
			_g_object_unref0 (_tmp15_);
		} else {
			const gchar* _tmp16_;
			gint _tmp17_;
			gint _tmp18_;
			SoupSession* _tmp19_;
			GProxyResolver* _tmp20_;
			_tmp16_ = proxy_url;
			_tmp17_ = strlen (_tmp16_);
			_tmp18_ = _tmp17_;
			if (_tmp18_ > 0) {
				g_warning ("web.vala:68: Invalid proxy URL. Falling back to the system proxy.");
			}
			_tmp19_ = proton_plus_utils_web__session;
			_tmp20_ = g_proxy_resolver_get_default ();
			soup_session_set_proxy_resolver (_tmp19_, _tmp20_);
		}
	} else {
		SoupSession* _tmp21_;
		GProxyResolver* _tmp22_;
		_tmp21_ = proton_plus_utils_web__session;
		_tmp22_ = g_proxy_resolver_get_default ();
		soup_session_set_proxy_resolver (_tmp21_, _tmp22_);
	}
	proton_plus_utils_web_applied_proxy_mode = proxy_mode;
	_tmp23_ = proxy_url;
	_tmp24_ = g_strdup (_tmp23_);
	_g_free0 (proton_plus_utils_web_applied_proxy_url);
	proton_plus_utils_web_applied_proxy_url = _tmp24_;
	_g_free0 (proxy_url);
}

static gboolean
proton_plus_utils_web_is_valid_proxy_url (const gchar* proxy_url)
{
	gchar** supported_schemes = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar** _tmp5_;
	gint supported_schemes_length1;
	gint _supported_schemes_size_;
	gint _tmp6_;
	gint _tmp7_;
	gchar** _tmp8_;
	gint _tmp8__length1;
	gboolean result;
	g_return_val_if_fail (proxy_url != NULL, FALSE);
	_tmp0_ = g_strdup ("http://");
	_tmp1_ = g_strdup ("https://");
	_tmp2_ = g_strdup ("socks://");
	_tmp3_ = g_strdup ("socks4://");
	_tmp4_ = g_strdup ("socks5://");
	_tmp5_ = g_new0 (gchar*, 5 + 1);
	_tmp5_[0] = _tmp0_;
	_tmp5_[1] = _tmp1_;
	_tmp5_[2] = _tmp2_;
	_tmp5_[3] = _tmp3_;
	_tmp5_[4] = _tmp4_;
	supported_schemes = _tmp5_;
	supported_schemes_length1 = 5;
	_supported_schemes_size_ = supported_schemes_length1;
	_tmp6_ = strlen (proxy_url);
	_tmp7_ = _tmp6_;
	if (_tmp7_ == 0) {
		result = FALSE;
		supported_schemes = (_vala_array_free (supported_schemes, supported_schemes_length1, (GDestroyNotify) g_free), NULL);
		return result;
	}
	_tmp8_ = supported_schemes;
	_tmp8__length1 = supported_schemes_length1;
	{
		gchar** scheme_collection = NULL;
		gint scheme_collection_length1 = 0;
		gint _scheme_collection_size_ = 0;
		gint scheme_it = 0;
		scheme_collection = _tmp8_;
		scheme_collection_length1 = _tmp8__length1;
		for (scheme_it = 0; scheme_it < scheme_collection_length1; scheme_it = scheme_it + 1) {
			gchar* _tmp9_;
			gchar* scheme = NULL;
			_tmp9_ = g_strdup (scheme_collection[scheme_it]);
			scheme = _tmp9_;
			{
				gboolean _tmp10_ = FALSE;
				const gchar* _tmp11_;
				_tmp11_ = scheme;
				if (g_str_has_prefix (proxy_url, _tmp11_)) {
					gint _tmp12_;
					gint _tmp13_;
					const gchar* _tmp14_;
					gint _tmp15_;
					gint _tmp16_;
					_tmp12_ = strlen (proxy_url);
					_tmp13_ = _tmp12_;
					_tmp14_ = scheme;
					_tmp15_ = strlen (_tmp14_);
					_tmp16_ = _tmp15_;
					_tmp10_ = _tmp13_ > _tmp16_;
				} else {
					_tmp10_ = FALSE;
				}
				if (_tmp10_) {
					result = TRUE;
					_g_free0 (scheme);
					supported_schemes = (_vala_array_free (supported_schemes, supported_schemes_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_g_free0 (scheme);
			}
		}
	}
	result = FALSE;
	supported_schemes = (_vala_array_free (supported_schemes, supported_schemes_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

static void
proton_plus_utils_web_get_request_data_free (gpointer _data)
{
	ProtonPlusUtilsWebGetRequestData* _data_;
	_data_ = _data;
	_g_free0 (_data_->uri);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	g_slice_free (ProtonPlusUtilsWebGetRequestData, _data_);
}

void
proton_plus_utils_web_get_request (const gchar* uri,
                                   ProtonPlusUtilsWebGetRequestType get_request_type,
                                   GCancellable* cancellable,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	ProtonPlusUtilsWebGetRequestData* _data_;
	gchar* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (uri != NULL);
	_data_ = g_slice_new0 (ProtonPlusUtilsWebGetRequestData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_web_get_request_data_free);
	_tmp0_ = g_strdup (uri);
	_g_free0 (_data_->uri);
	_data_->uri = _tmp0_;
	_data_->get_request_type = get_request_type;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	proton_plus_utils_web_get_request_co (_data_);
}

ProtonPlusUtilsWebResponse*
proton_plus_utils_web_get_request_finish (GAsyncResult* _res_)
{
	ProtonPlusUtilsWebResponse* result;
	ProtonPlusUtilsWebGetRequestData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
proton_plus_utils_web_get_request_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	ProtonPlusUtilsWebGetRequestData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_utils_web_get_request_co (_data_);
}

static gboolean
proton_plus_utils_web_get_request_co (ProtonPlusUtilsWebGetRequestData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = soup_message_new ("GET", _data_->uri);
	_data_->message = _data_->_tmp0_;
	_data_->_tmp1_ = proton_plus_globals_SETTINGS;
	if (_data_->_tmp1_ != NULL) {
		if (_data_->get_request_type == PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITHUB) {
			_data_->_tmp2_ = TRUE;
		} else {
			_data_->_tmp2_ = _data_->get_request_type == PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_STEAMTINKERLAUNCH;
		}
		if (_data_->_tmp2_) {
			_data_->_tmp3_ = proton_plus_globals_SETTINGS;
			_data_->_tmp4_ = g_settings_get_string (_data_->_tmp3_, "github-api-key");
			_data_->key = _data_->_tmp4_;
			_data_->_tmp5_ = _data_->key;
			_data_->_tmp6_ = strlen (_data_->_tmp5_);
			_data_->_tmp7_ = _data_->_tmp6_;
			if (_data_->_tmp7_ > 0) {
				_data_->_tmp8_ = _data_->message;
				_data_->_tmp9_ = soup_message_get_request_headers (_data_->_tmp8_);
				_data_->_tmp10_ = _data_->_tmp9_;
				_data_->_tmp11_ = _data_->key;
				_data_->_tmp12_ = g_strdup_printf ("token %s", _data_->_tmp11_);
				_data_->_tmp13_ = _data_->_tmp12_;
				soup_message_headers_append (_data_->_tmp10_, "Authorization", _data_->_tmp13_);
				_g_free0 (_data_->_tmp13_);
			}
			_g_free0 (_data_->key);
		}
		if (_data_->get_request_type == PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITLAB) {
			_data_->_tmp14_ = proton_plus_globals_SETTINGS;
			_data_->_tmp15_ = g_settings_get_string (_data_->_tmp14_, "gitlab-api-key");
			_data_->_vala1_key = _data_->_tmp15_;
			_data_->_tmp16_ = _data_->_vala1_key;
			_data_->_tmp17_ = strlen (_data_->_tmp16_);
			_data_->_tmp18_ = _data_->_tmp17_;
			if (_data_->_tmp18_ > 0) {
				_data_->_tmp19_ = _data_->message;
				_data_->_tmp20_ = soup_message_get_request_headers (_data_->_tmp19_);
				_data_->_tmp21_ = _data_->_tmp20_;
				_data_->_tmp22_ = _data_->_vala1_key;
				_data_->_tmp23_ = g_strdup_printf ("Bearer %s", _data_->_tmp22_);
				_data_->_tmp24_ = _data_->_tmp23_;
				soup_message_headers_append (_data_->_tmp21_, "Authorization", _data_->_tmp24_);
				_g_free0 (_data_->_tmp24_);
			}
			_g_free0 (_data_->_vala1_key);
		}
		if (_data_->get_request_type == PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_STEAMTINKERLAUNCH) {
			_data_->_tmp25_ = _data_->message;
			_data_->_tmp26_ = soup_message_get_request_headers (_data_->_tmp25_);
			_data_->_tmp27_ = _data_->_tmp26_;
			soup_message_headers_append (_data_->_tmp27_, "Accept", "application/vnd.github+json");
			_data_->_tmp28_ = _data_->message;
			_data_->_tmp29_ = soup_message_get_request_headers (_data_->_tmp28_);
			_data_->_tmp30_ = _data_->_tmp29_;
			soup_message_headers_append (_data_->_tmp30_, "X-GitHub-Api-Version", "2022-11-28");
		}
	}
	_data_->_tmp31_ = _data_->message;
	_data_->_state_ = 1;
	proton_plus_utils_web_send_request (_data_->_tmp31_, _data_->cancellable, proton_plus_utils_web_get_request_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp32_ = proton_plus_utils_web_send_request_finish (_data_->_res_);
	_data_->response = _data_->_tmp32_;
	_data_->_tmp33_ = _data_->response;
	if (_data_->_tmp33_ == NULL) {
		_data_->_tmp34_ = proton_plus_utils_web_response_new ();
		_data_->result = _data_->_tmp34_;
		_g_object_unref0 (_data_->response);
		_g_object_unref0 (_data_->message);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp35_ = _data_->response;
	_data_->_tmp36_ = proton_plus_utils_web_response_get_is_successful (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp35_, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse));
	_data_->_tmp37_ = _data_->_tmp36_;
	if (_data_->_tmp37_) {
		_data_->_tmp38_ = _data_->response;
		_data_->_tmp39_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp38_, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse));
		_data_->result = _data_->_tmp39_;
		_g_object_unref0 (_data_->response);
		_g_object_unref0 (_data_->message);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp41_ = _data_->response;
	_data_->_tmp42_ = proton_plus_utils_web_response_get_status_code (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp41_, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse));
	_data_->_tmp43_ = _data_->_tmp42_;
	if (_data_->_tmp43_ == 403) {
		_data_->_tmp40_ = TRUE;
	} else {
		_data_->_tmp44_ = _data_->response;
		_data_->_tmp45_ = proton_plus_utils_web_response_get_status_code (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp44_, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse));
		_data_->_tmp46_ = _data_->_tmp45_;
		_data_->_tmp40_ = _data_->_tmp46_ == 429;
	}
	if (_data_->_tmp40_) {
		_data_->_tmp47_ = _data_->response;
		proton_plus_utils_web_response_set_code (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp47_, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse), PROTON_PLUS_RETURN_CODE_API_LIMIT_REACHED);
	} else {
		_data_->_tmp49_ = _data_->response;
		_data_->_tmp50_ = proton_plus_utils_web_response_get_status_code (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp49_, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse));
		_data_->_tmp51_ = _data_->_tmp50_;
		if (_data_->_tmp51_ == 401) {
			if (_data_->get_request_type == PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITHUB) {
				_data_->_tmp54_ = TRUE;
			} else {
				_data_->_tmp54_ = _data_->get_request_type == PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITLAB;
			}
			if (_data_->_tmp54_) {
				_data_->_tmp53_ = TRUE;
			} else {
				_data_->_tmp53_ = _data_->get_request_type == PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_FORGEJO;
			}
			if (_data_->_tmp53_) {
				_data_->_tmp52_ = TRUE;
			} else {
				_data_->_tmp52_ = _data_->get_request_type == PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_STEAMTINKERLAUNCH;
			}
			_data_->_tmp48_ = _data_->_tmp52_;
		} else {
			_data_->_tmp48_ = FALSE;
		}
		if (_data_->_tmp48_) {
			_data_->_tmp55_ = _data_->response;
			proton_plus_utils_web_response_set_code (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp55_, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse), PROTON_PLUS_RETURN_CODE_INVALID_ACCESS_TOKEN);
		}
	}
	_data_->_tmp56_ = _data_->response;
	_data_->_tmp57_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp56_, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse));
	_data_->result = _data_->_tmp57_;
	_g_object_unref0 (_data_->response);
	_g_object_unref0 (_data_->message);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
proton_plus_utils_web_send_request_data_free (gpointer _data)
{
	ProtonPlusUtilsWebSendRequestData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->message);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	g_slice_free (ProtonPlusUtilsWebSendRequestData, _data_);
}

static void
proton_plus_utils_web_send_request (SoupMessage* message,
                                    GCancellable* cancellable,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	ProtonPlusUtilsWebSendRequestData* _data_;
	SoupMessage* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (message != NULL);
	_data_ = g_slice_new0 (ProtonPlusUtilsWebSendRequestData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_web_send_request_data_free);
	_tmp0_ = _g_object_ref0 (message);
	_g_object_unref0 (_data_->message);
	_data_->message = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	proton_plus_utils_web_send_request_co (_data_);
}

static ProtonPlusUtilsWebResponse*
proton_plus_utils_web_send_request_finish (GAsyncResult* _res_)
{
	ProtonPlusUtilsWebResponse* result;
	ProtonPlusUtilsWebSendRequestData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
proton_plus_utils_web_send_request_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	ProtonPlusUtilsWebSendRequestData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_utils_web_send_request_co (_data_);
}

static gboolean
proton_plus_utils_web_send_request_co (ProtonPlusUtilsWebSendRequestData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = proton_plus_utils_web_response_new ();
	_data_->response = _data_->_tmp0_;
	{
		_data_->_tmp1_ = proton_plus_utils_web_get_current_session ();
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_state_ = 1;
		soup_session_send_and_read_async (_data_->_tmp2_, _data_->message, G_PRIORITY_DEFAULT, _data_->cancellable, proton_plus_utils_web_send_request_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp3_ = soup_session_send_and_read_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
		_data_->bytes = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp4_ = _data_->response;
		g_object_get (_data_->message, "status-code", &_data_->_tmp5_, NULL);
		_data_->_tmp6_ = _data_->_tmp5_;
		proton_plus_utils_web_response_set_status_code (_data_->_tmp4_, (gint) _data_->_tmp6_);
		_data_->_tmp7_ = _data_->response;
		_data_->_tmp8_ = soup_message_get_reason_phrase (_data_->message);
		_data_->_tmp9_ = _data_->_tmp8_;
		proton_plus_utils_web_response_set_error_message (_data_->_tmp7_, _data_->_tmp9_);
		_data_->_tmp10_ = _data_->response;
		_data_->_tmp11_ = proton_plus_utils_web_response_get_is_successful (_data_->_tmp10_);
		_data_->_tmp12_ = _data_->_tmp11_;
		if (!_data_->_tmp12_) {
			_data_->result = _data_->response;
			_g_bytes_unref0 (_data_->bytes);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp13_ = _data_->response;
		_data_->_tmp14_ = _data_->bytes;
		_data_->_tmp15_ = 0;
		_data_->_tmp16_ = g_bytes_get_data (_data_->_tmp14_, &_data_->_tmp15_);
		_data_->_tmp17_ = proton_plus_utils_parser_data_to_string (_data_->_tmp16_, (gint) _data_->_tmp15_);
		_data_->_tmp18_ = _data_->_tmp17_;
		proton_plus_utils_web_response_set_body (_data_->_tmp13_, _data_->_tmp18_);
		_g_free0 (_data_->_tmp18_);
		_data_->_tmp19_ = _data_->response;
		proton_plus_utils_web_response_set_code (_data_->_tmp19_, PROTON_PLUS_RETURN_CODE_VALID_REQUEST);
		_data_->result = _data_->response;
		_g_bytes_unref0 (_data_->bytes);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp21_ = _data_->e;
		if (g_error_matches (_data_->_tmp21_, SOUP_SESSION_ERROR, SOUP_SESSION_ERROR_PARSING)) {
			_data_->_tmp20_ = TRUE;
		} else {
			_data_->_tmp22_ = _data_->e;
			_data_->_tmp20_ = _data_->_tmp22_->domain == g_tls_error_quark ();
		}
		if (_data_->_tmp20_) {
			_data_->_tmp23_ = _data_->response;
			proton_plus_utils_web_response_set_code (_data_->_tmp23_, PROTON_PLUS_RETURN_CODE_TLS_HANDSHAKE_ERROR);
		} else {
			_data_->_tmp25_ = _data_->e;
			if (g_error_matches (_data_->_tmp25_, G_IO_ERROR, G_IO_ERROR_HOST_UNREACHABLE)) {
				_data_->_tmp24_ = TRUE;
			} else {
				_data_->_tmp26_ = _data_->e;
				_data_->_tmp24_ = g_error_matches (_data_->_tmp26_, G_IO_ERROR, G_IO_ERROR_NETWORK_UNREACHABLE);
			}
			if (_data_->_tmp24_) {
				_data_->_tmp27_ = _data_->response;
				proton_plus_utils_web_response_set_code (_data_->_tmp27_, PROTON_PLUS_RETURN_CODE_CONNECTION_ISSUE);
			} else {
				_data_->_tmp28_ = _data_->e;
				if (g_error_matches (_data_->_tmp28_, G_IO_ERROR, G_IO_ERROR_CONNECTION_REFUSED)) {
					_data_->_tmp29_ = _data_->response;
					proton_plus_utils_web_response_set_code (_data_->_tmp29_, PROTON_PLUS_RETURN_CODE_CONNECTION_REFUSED);
				} else {
					_data_->_tmp30_ = _data_->e;
					if (g_error_matches (_data_->_tmp30_, G_IO_ERROR, G_IO_ERROR_HOST_NOT_FOUND)) {
						_data_->_tmp31_ = _data_->response;
						proton_plus_utils_web_response_set_code (_data_->_tmp31_, PROTON_PLUS_RETURN_CODE_CONNECTION_UNKNOWN);
					} else {
						_data_->_tmp32_ = _data_->e;
						if (!g_error_matches (_data_->_tmp32_, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
							_data_->_tmp33_ = _data_->e;
							_data_->_tmp34_ = _data_->_tmp33_->message;
							g_warning ("web.vala:164: %s", _data_->_tmp34_);
						}
					}
				}
			}
		}
		_data_->_tmp35_ = _data_->response;
		_data_->_tmp36_ = _data_->e;
		_data_->_tmp37_ = _data_->_tmp36_->message;
		proton_plus_utils_web_response_set_error_message (_data_->_tmp35_, _data_->_tmp37_);
		_data_->result = _data_->response;
		_g_error_free0 (_data_->e);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	_g_object_unref0 (_data_->response);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
	g_clear_error (&_data_->_inner_error0_);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gdouble*
_double_dup (gdouble* self)
{
	gdouble* dup;
	dup = g_new0 (gdouble, 1);
	memcpy (dup, self, sizeof (gdouble));
	return dup;
}

static gpointer
__double_dup0 (gpointer self)
{
	return self ? _double_dup (self) : NULL;
}

static void
proton_plus_utils_web_report_download_progress (ProtonPlusUtilsWebprogress_callback progress_callback,
                                                gpointer progress_callback_target,
                                                gboolean is_percent,
                                                gint64 bytes_downloaded,
                                                gint64 server_download_size,
                                                gint64 start_time)
{
	gint64 elapsed_us = 0LL;
	gdouble elapsed_s = 0.0;
	gdouble _tmp0_ = 0.0;
	gdouble speed_kbps = 0.0;
	gdouble _tmp1_ = 0.0;
	gdouble speed_bps = 0.0;
	gdouble* remaining_seconds = NULL;
	gboolean _tmp2_ = FALSE;
	gint64 _tmp5_ = 0LL;
	gint64 progress = 0LL;
	gdouble* _tmp6_;
	elapsed_us = g_get_monotonic_time () - start_time;
	elapsed_s = elapsed_us / 1000000.0;
	if (elapsed_s > ((gdouble) 0)) {
		_tmp0_ = (bytes_downloaded / 1024.0) / elapsed_s;
	} else {
		_tmp0_ = 0.0;
	}
	speed_kbps = _tmp0_;
	if (elapsed_s > ((gdouble) 0)) {
		_tmp1_ = bytes_downloaded / elapsed_s;
	} else {
		_tmp1_ = 0.0;
	}
	speed_bps = _tmp1_;
	remaining_seconds = NULL;
	if (is_percent) {
		_tmp2_ = speed_bps > 0.0;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		gint64 bytes_left = 0LL;
		gdouble _tmp3_;
		gdouble* _tmp4_;
		bytes_left = server_download_size - bytes_downloaded;
		_tmp3_ = bytes_left / speed_bps;
		_tmp4_ = __double_dup0 (&_tmp3_);
		_g_free0 (remaining_seconds);
		remaining_seconds = _tmp4_;
	}
	if (!is_percent) {
		_tmp5_ = bytes_downloaded;
	} else {
		_tmp5_ = (gint64) ((((gdouble) bytes_downloaded) / server_download_size) * 100);
	}
	progress = _tmp5_;
	_tmp6_ = remaining_seconds;
	progress_callback (is_percent, progress, speed_kbps, _tmp6_, progress_callback_target);
	_g_free0 (remaining_seconds);
}

static void
proton_plus_utils_web_cleanup_partial_download_data_free (gpointer _data)
{
	ProtonPlusUtilsWebCleanupPartialDownloadData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->file);
	_g_object_unref0 (_data_->output_stream);
	g_slice_free (ProtonPlusUtilsWebCleanupPartialDownloadData, _data_);
}

static void
proton_plus_utils_web_cleanup_partial_download (GFile* file,
                                                GFileOutputStream* output_stream,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_)
{
	ProtonPlusUtilsWebCleanupPartialDownloadData* _data_;
	GFile* _tmp0_;
	GFileOutputStream* _tmp1_;
	g_return_if_fail (file != NULL);
	_data_ = g_slice_new0 (ProtonPlusUtilsWebCleanupPartialDownloadData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_web_cleanup_partial_download_data_free);
	_tmp0_ = _g_object_ref0 (file);
	_g_object_unref0 (_data_->file);
	_data_->file = _tmp0_;
	_tmp1_ = _g_object_ref0 (output_stream);
	_g_object_unref0 (_data_->output_stream);
	_data_->output_stream = _tmp1_;
	proton_plus_utils_web_cleanup_partial_download_co (_data_);
}

static void
proton_plus_utils_web_cleanup_partial_download_finish (GAsyncResult* _res_)
{
	ProtonPlusUtilsWebCleanupPartialDownloadData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
proton_plus_utils_web_cleanup_partial_download_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	ProtonPlusUtilsWebCleanupPartialDownloadData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_utils_web_cleanup_partial_download_co (_data_);
}

static gboolean
proton_plus_utils_web_cleanup_partial_download_co (ProtonPlusUtilsWebCleanupPartialDownloadData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->output_stream != NULL) {
		{
			_data_->_state_ = 1;
			g_output_stream_close_async ((GOutputStream*) _data_->output_stream, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_cleanup_partial_download_ready, _data_);
			return FALSE;
			_state_1:
			g_output_stream_close_finish ((GOutputStream*) _data_->output_stream, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp0_ = _data_->e;
			_data_->_tmp1_ = _data_->_tmp0_->message;
			_data_->_tmp2_ = g_strdup_printf ("Could not close partial download: %s", _data_->_tmp1_);
			_data_->_tmp3_ = _data_->_tmp2_;
			g_warning ("web.vala:203: %s", _data_->_tmp3_);
			_g_free0 (_data_->_tmp3_);
			_g_error_free0 (_data_->e);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	{
		if (g_file_query_exists (_data_->file, NULL)) {
			_data_->_state_ = 2;
			g_file_delete_async (_data_->file, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_cleanup_partial_download_ready, _data_);
			return FALSE;
			_state_2:
			g_file_delete_finish (_data_->file, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp4_ = _data_->_vala1_e;
		_data_->_tmp5_ = _data_->_tmp4_->message;
		_data_->_tmp6_ = g_strdup_printf ("Could not remove partial download: %s", _data_->_tmp5_);
		_data_->_tmp7_ = _data_->_tmp6_;
		g_warning ("web.vala:211: %s", _data_->_tmp7_);
		_g_free0 (_data_->_tmp7_);
		_g_error_free0 (_data_->_vala1_e);
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gboolean
proton_plus_utils_web_should_retry_download_error (GError* _error_,
                                                   gint attempt)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (_error_ != NULL, FALSE);
	if (g_error_matches (_error_, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)) {
		_tmp0_ = attempt < PROTON_PLUS_UTILS_WEB_MAX_DOWNLOAD_ATTEMPTS;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static gchar*
proton_plus_utils_web_get_download_error_message (GError* _error_)
{
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (_error_ != NULL, NULL);
	if (g_error_matches (_error_, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (_ ("The download timed out. Check your connection and try again."));
		result = _tmp0_;
		return result;
	}
	_tmp1_ = _error_->message;
	_tmp2_ = g_strdup (_tmp1_);
	result = _tmp2_;
	return result;
}

static void
proton_plus_utils_web_download_once_data_free (gpointer _data)
{
	ProtonPlusUtilsWebDownloadOnceData* _data_;
	_data_ = _data;
	_g_free0 (_data_->url);
	_g_object_unref0 (_data_->file);
	_g_object_unref0 (_data_->cancellable);
	g_slice_free (ProtonPlusUtilsWebDownloadOnceData, _data_);
}

static void
proton_plus_utils_web_download_once (const gchar* url,
                                     GFile* file,
                                     GCancellable* cancellable,
                                     ProtonPlusUtilsWebprogress_callback progress_callback,
                                     gpointer progress_callback_target,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	ProtonPlusUtilsWebDownloadOnceData* _data_;
	gchar* _tmp0_;
	GFile* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (url != NULL);
	g_return_if_fail (file != NULL);
	_data_ = g_slice_new0 (ProtonPlusUtilsWebDownloadOnceData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_web_download_once_data_free);
	_tmp0_ = g_strdup (url);
	_g_free0 (_data_->url);
	_data_->url = _tmp0_;
	_tmp1_ = _g_object_ref0 (file);
	_g_object_unref0 (_data_->file);
	_data_->file = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	_data_->progress_callback = progress_callback;
	_data_->progress_callback_target = progress_callback_target;
	proton_plus_utils_web_download_once_co (_data_);
}

static gboolean
proton_plus_utils_web_download_once_finish (GAsyncResult* _res_,
                                            gchar** error_message,
                                            GError** error)
{
	gboolean result;
	ProtonPlusUtilsWebDownloadOnceData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		gboolean _tmp0_ = FALSE;
		return _tmp0_;
	}
	if (error_message) {
		*error_message = _data_->error_message;
	} else {
		_g_free0 (_data_->error_message);
	}
	_data_->error_message = NULL;
	result = _data_->result;
	return result;
}

static void
proton_plus_utils_web_download_once_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_)
{
	ProtonPlusUtilsWebDownloadOnceData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_utils_web_download_once_co (_data_);
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static gboolean
proton_plus_utils_web_download_once_co (ProtonPlusUtilsWebDownloadOnceData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		case 5:
		goto _state_5;
		case 6:
		goto _state_6;
		case 7:
		goto _state_7;
		case 8:
		goto _state_8;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_g_free0 (_data_->error_message);
	_data_->error_message = NULL;
	_data_->output_stream = NULL;
	_data_->has_partial_file = FALSE;
	{
		static const gsize max_chunk_size = (gsize) (64 * 1024);
		static const gint64 progress_report_interval_us = (gint64) (100 * 1000);
		_data_->_tmp0_ = soup_message_new ("GET", _data_->url);
		_data_->soup_message = _data_->_tmp0_;
		_data_->_tmp1_ = proton_plus_utils_web_get_current_session ();
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = _data_->soup_message;
		_data_->_state_ = 1;
		soup_session_send_async (_data_->_tmp2_, _data_->_tmp3_, G_PRIORITY_DEFAULT, _data_->cancellable, proton_plus_utils_web_download_once_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp4_ = soup_session_send_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
		_data_->input_stream = _data_->_tmp4_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->soup_message);
			goto __catch0_g_error;
		}
		_data_->_tmp5_ = _data_->soup_message;
		g_object_get (_data_->_tmp5_, "status-code", &_data_->_tmp6_, NULL);
		_data_->_tmp7_ = _data_->_tmp6_;
		if (_data_->_tmp7_ != ((guint) 200)) {
			_data_->_tmp8_ = _data_->soup_message;
			_data_->_tmp9_ = soup_message_get_reason_phrase (_data_->_tmp8_);
			_data_->_tmp10_ = _data_->_tmp9_;
			g_warning ("web.vala:242: %s", _data_->_tmp10_);
			_data_->_tmp11_ = _data_->soup_message;
			_data_->_tmp12_ = soup_message_get_reason_phrase (_data_->_tmp11_);
			_data_->_tmp13_ = _data_->_tmp12_;
			_data_->_tmp14_ = g_strdup (_data_->_tmp13_);
			_g_free0 (_data_->error_message);
			_data_->error_message = _data_->_tmp14_;
			_data_->result = FALSE;
			_g_object_unref0 (_data_->input_stream);
			_g_object_unref0 (_data_->soup_message);
			_g_object_unref0 (_data_->output_stream);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_state_ = 2;
		g_file_create_async (_data_->file, G_FILE_CREATE_REPLACE_DESTINATION, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_download_once_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp16_ = g_file_create_finish (_data_->file, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp15_ = _data_->_tmp16_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->input_stream);
			_g_object_unref0 (_data_->soup_message);
			goto __catch0_g_error;
		}
		_data_->_tmp17_ = _data_->_tmp15_;
		_data_->_tmp15_ = NULL;
		_g_object_unref0 (_data_->output_stream);
		_data_->output_stream = _data_->_tmp17_;
		_data_->has_partial_file = TRUE;
		_data_->_tmp18_ = _data_->soup_message;
		_data_->_tmp19_ = soup_message_get_response_headers (_data_->_tmp18_);
		_data_->server_download_size = soup_message_headers_get_content_length (_data_->_tmp19_);
		_data_->is_percent = _data_->server_download_size > ((gint64) 0);
		_data_->bytes_downloaded = (gint64) 0;
		if (_data_->progress_callback != NULL) {
			_data_->_tmp20_ = (gdouble) 0;
			_data_->progress_callback (_data_->is_percent, (gint64) 0, (gdouble) 0, &_data_->_tmp20_, _data_->progress_callback_target);
		}
		_data_->is_canceled = FALSE;
		_data_->start_time = g_get_monotonic_time ();
		_data_->last_progress_report_time = _data_->start_time;
		while (TRUE) {
			if (_data_->cancellable != NULL) {
				_data_->_tmp21_ = g_cancellable_is_cancelled (_data_->cancellable);
			} else {
				_data_->_tmp21_ = FALSE;
			}
			if (_data_->_tmp21_) {
				_data_->is_canceled = TRUE;
				break;
			}
			_data_->_tmp22_ = proton_plus_utils_download_manager_get_instance ();
			_data_->_tmp23_ = _data_->_tmp22_;
			_data_->_tmp24_ = _g_object_ref0 (_data_->_tmp23_);
			_data_->download_manager = _data_->_tmp24_;
			_data_->_tmp25_ = _data_->download_manager;
			_data_->_tmp26_ = proton_plus_utils_download_manager_get_speed_limit_bps (_data_->_tmp25_);
			_data_->_tmp27_ = _data_->_tmp26_;
			_data_->speed_limit_bps_before_read = _data_->_tmp27_;
			_data_->_tmp28_ = _data_->download_manager;
			_data_->_tmp29_ = proton_plus_utils_download_manager_get_throttle_generation (_data_->_tmp28_);
			_data_->_tmp30_ = _data_->_tmp29_;
			_data_->throttle_generation_before_read = _data_->_tmp30_;
			_data_->chunk_size = max_chunk_size;
			if (_data_->speed_limit_bps_before_read > ((gint64) 0)) {
				_data_->suggested_chunk = _data_->speed_limit_bps_before_read / 8;
				if (_data_->suggested_chunk < ((gint64) 1024)) {
					_data_->suggested_chunk = (gint64) 1024;
				}
				if (_data_->suggested_chunk < ((gint64) max_chunk_size)) {
					_data_->chunk_size = (gsize) _data_->suggested_chunk;
				}
			}
			_data_->transfer_started_us = g_get_monotonic_time ();
			_data_->_tmp31_ = _data_->input_stream;
			_data_->_state_ = 3;
			g_input_stream_read_bytes_async (_data_->_tmp31_, _data_->chunk_size, G_PRIORITY_DEFAULT, _data_->cancellable, proton_plus_utils_web_download_once_ready, _data_);
			return FALSE;
			_state_3:
			_data_->_tmp32_ = g_input_stream_read_bytes_finish (_data_->_tmp31_, _data_->_res_, &_data_->_inner_error0_);
			_data_->chunk = _data_->_tmp32_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->download_manager);
				_g_object_unref0 (_data_->_tmp15_);
				_g_object_unref0 (_data_->input_stream);
				_g_object_unref0 (_data_->soup_message);
				goto __catch0_g_error;
			}
			_data_->_tmp33_ = _data_->chunk;
			if (g_bytes_get_size (_data_->_tmp33_) == ((gsize) 0)) {
				_g_bytes_unref0 (_data_->chunk);
				_g_object_unref0 (_data_->download_manager);
				break;
			}
			_data_->_tmp34_ = _data_->output_stream;
			_data_->_tmp35_ = _data_->chunk;
			_data_->_tmp36_ = 0;
			_data_->_tmp37_ = g_bytes_get_data (_data_->_tmp35_, &_data_->_tmp36_);
			_data_->_tmp38_ = 0UL;
			_data_->_state_ = 4;
			g_output_stream_write_all_async ((GOutputStream*) _data_->_tmp34_, _data_->_tmp37_, (gsize) _data_->_tmp36_, G_PRIORITY_DEFAULT, _data_->cancellable, proton_plus_utils_web_download_once_ready, _data_);
			return FALSE;
			_state_4:
			g_output_stream_write_all_finish ((GOutputStream*) _data_->_tmp34_, _data_->_res_, &_data_->_tmp38_, &_data_->_inner_error0_);
			_data_->bytes_written = _data_->_tmp38_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_bytes_unref0 (_data_->chunk);
				_g_object_unref0 (_data_->download_manager);
				_g_object_unref0 (_data_->_tmp15_);
				_g_object_unref0 (_data_->input_stream);
				_g_object_unref0 (_data_->soup_message);
				goto __catch0_g_error;
			}
			_data_->bytes_downloaded += (gint64) _data_->bytes_written;
			_data_->_tmp39_ = _data_->download_manager;
			_data_->_state_ = 5;
			proton_plus_utils_download_manager_throttle_global_download_bytes (_data_->_tmp39_, (gint64) _data_->bytes_written, _data_->transfer_started_us, _data_->throttle_generation_before_read, _data_->cancellable, proton_plus_utils_web_download_once_ready, _data_);
			return FALSE;
			_state_5:
			proton_plus_utils_download_manager_throttle_global_download_bytes_finish (_data_->_tmp39_, _data_->_res_);
			if (_data_->cancellable != NULL) {
				_data_->_tmp40_ = g_cancellable_is_cancelled (_data_->cancellable);
			} else {
				_data_->_tmp40_ = FALSE;
			}
			if (_data_->_tmp40_) {
				_data_->is_canceled = TRUE;
				_g_bytes_unref0 (_data_->chunk);
				_g_object_unref0 (_data_->download_manager);
				break;
			}
			_data_->now = g_get_monotonic_time ();
			if (_data_->progress_callback != NULL) {
				_data_->_tmp41_ = (_data_->now - _data_->last_progress_report_time) >= progress_report_interval_us;
			} else {
				_data_->_tmp41_ = FALSE;
			}
			if (_data_->_tmp41_) {
				proton_plus_utils_web_report_download_progress (_data_->progress_callback, _data_->progress_callback_target, _data_->is_percent, _data_->bytes_downloaded, _data_->server_download_size, _data_->start_time);
				_data_->last_progress_report_time = _data_->now;
			}
			_g_bytes_unref0 (_data_->chunk);
			_g_object_unref0 (_data_->download_manager);
		}
		if (!_data_->is_canceled) {
			_data_->_tmp42_ = _data_->progress_callback != NULL;
		} else {
			_data_->_tmp42_ = FALSE;
		}
		if (_data_->_tmp42_) {
			proton_plus_utils_web_report_download_progress (_data_->progress_callback, _data_->progress_callback_target, _data_->is_percent, _data_->bytes_downloaded, _data_->server_download_size, _data_->start_time);
		}
		_data_->_tmp43_ = _data_->output_stream;
		_data_->_state_ = 6;
		g_output_stream_close_async ((GOutputStream*) _data_->_tmp43_, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_download_once_ready, _data_);
		return FALSE;
		_state_6:
		g_output_stream_close_finish ((GOutputStream*) _data_->_tmp43_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->_tmp15_);
			_g_object_unref0 (_data_->input_stream);
			_g_object_unref0 (_data_->soup_message);
			goto __catch0_g_error;
		}
		_g_object_unref0 (_data_->output_stream);
		_data_->output_stream = NULL;
		if (_data_->is_canceled) {
			_data_->_tmp44_ = _data_->output_stream;
			_data_->_state_ = 7;
			proton_plus_utils_web_cleanup_partial_download (_data_->file, _data_->_tmp44_, proton_plus_utils_web_download_once_ready, _data_);
			return FALSE;
			_state_7:
			proton_plus_utils_web_cleanup_partial_download_finish (_data_->_res_);
			_data_->result = FALSE;
			_g_object_unref0 (_data_->_tmp15_);
			_g_object_unref0 (_data_->input_stream);
			_g_object_unref0 (_data_->soup_message);
			_g_object_unref0 (_data_->output_stream);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->has_partial_file = FALSE;
		_data_->result = TRUE;
		_g_object_unref0 (_data_->_tmp15_);
		_g_object_unref0 (_data_->input_stream);
		_g_object_unref0 (_data_->soup_message);
		_g_object_unref0 (_data_->output_stream);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		if (_data_->has_partial_file) {
			_data_->_tmp45_ = _data_->output_stream;
			_data_->_state_ = 8;
			proton_plus_utils_web_cleanup_partial_download (_data_->file, _data_->_tmp45_, proton_plus_utils_web_download_once_ready, _data_);
			return FALSE;
			_state_8:
			proton_plus_utils_web_cleanup_partial_download_finish (_data_->_res_);
		}
		_data_->_tmp46_ = _data_->e;
		_data_->_tmp47_ = _g_error_copy0 (_data_->_tmp46_);
		_data_->_inner_error0_ = _data_->_tmp47_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	__finally0:
	g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
	_g_object_unref0 (_data_->output_stream);
	_g_free0 (_data_->error_message);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
proton_plus_utils_web_download_data_free (gpointer _data)
{
	ProtonPlusUtilsWebDownloadData* _data_;
	_data_ = _data;
	_g_free0 (_data_->url);
	_g_free0 (_data_->path);
	_g_object_unref0 (_data_->cancellable);
	g_slice_free (ProtonPlusUtilsWebDownloadData, _data_);
}

void
proton_plus_utils_web_download (const gchar* url,
                                const gchar* path,
                                GCancellable* cancellable,
                                ProtonPlusUtilsWebprogress_callback progress_callback,
                                gpointer progress_callback_target,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	ProtonPlusUtilsWebDownloadData* _data_;
	gchar* _tmp0_;
	gchar* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (url != NULL);
	g_return_if_fail (path != NULL);
	_data_ = g_slice_new0 (ProtonPlusUtilsWebDownloadData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_web_download_data_free);
	_tmp0_ = g_strdup (url);
	_g_free0 (_data_->url);
	_data_->url = _tmp0_;
	_tmp1_ = g_strdup (path);
	_g_free0 (_data_->path);
	_data_->path = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	_data_->progress_callback = progress_callback;
	_data_->progress_callback_target = progress_callback_target;
	proton_plus_utils_web_download_co (_data_);
}

gboolean
proton_plus_utils_web_download_finish (GAsyncResult* _res_,
                                       gchar** error_message)
{
	gboolean result;
	ProtonPlusUtilsWebDownloadData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		gboolean _tmp0_ = FALSE;
		return _tmp0_;
	}
	if (error_message) {
		*error_message = _data_->error_message;
	} else {
		_g_free0 (_data_->error_message);
	}
	_data_->error_message = NULL;
	result = _data_->result;
	return result;
}

static void
proton_plus_utils_web_download_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	ProtonPlusUtilsWebDownloadData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_utils_web_download_co (_data_);
}

static gboolean
proton_plus_utils_web_download_co (ProtonPlusUtilsWebDownloadData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_g_free0 (_data_->error_message);
	_data_->error_message = NULL;
	_data_->_tmp0_ = g_file_new_for_path (_data_->path);
	_data_->file = _data_->_tmp0_;
	{
		_data_->attempt = 1;
		{
			_data_->_tmp1_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp1_) {
					_data_->_tmp2_ = _data_->attempt;
					_data_->attempt = _data_->_tmp2_ + 1;
				}
				_data_->_tmp1_ = FALSE;
				if (!(_data_->attempt <= PROTON_PLUS_UTILS_WEB_MAX_DOWNLOAD_ATTEMPTS)) {
					break;
				}
				{
					_data_->_tmp4_ = _data_->file;
					_data_->_tmp5_ = NULL;
					_data_->_state_ = 1;
					proton_plus_utils_web_download_once (_data_->url, _data_->_tmp4_, _data_->cancellable, _data_->progress_callback, _data_->progress_callback_target, proton_plus_utils_web_download_ready, _data_);
					return FALSE;
					_state_1:
					_data_->_tmp6_ = proton_plus_utils_web_download_once_finish (_data_->_res_, &_data_->_tmp5_, &_data_->_inner_error0_);
					_g_free0 (_data_->error_message);
					_data_->error_message = _data_->_tmp5_;
					_data_->_tmp3_ = _data_->_tmp6_;
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						goto __catch0_g_error;
					}
					_data_->result = _data_->_tmp3_;
					_g_object_unref0 (_data_->file);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				goto __finally0;
				__catch0_g_error:
				{
					_data_->e = _data_->_inner_error0_;
					_data_->_inner_error0_ = NULL;
					if (_data_->cancellable != NULL) {
						_data_->_tmp7_ = g_cancellable_is_cancelled (_data_->cancellable);
					} else {
						_data_->_tmp7_ = FALSE;
					}
					if (_data_->_tmp7_) {
						_data_->result = FALSE;
						_g_error_free0 (_data_->e);
						_g_object_unref0 (_data_->file);
						g_task_return_pointer (_data_->_async_result, _data_, NULL);
						if (_data_->_state_ != 0) {
							while (!g_task_get_completed (_data_->_async_result)) {
								g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
							}
						}
						g_object_unref (_data_->_async_result);
						return FALSE;
					}
					_data_->_tmp8_ = _data_->e;
					if (proton_plus_utils_web_should_retry_download_error (_data_->_tmp8_, _data_->attempt)) {
						_data_->_tmp9_ = _data_->e;
						_data_->_tmp10_ = _data_->_tmp9_->message;
						_data_->_tmp11_ = g_strdup_printf ("Download timed out; retrying once: %s", _data_->_tmp10_);
						_data_->_tmp12_ = _data_->_tmp11_;
						g_warning ("web.vala:359: %s", _data_->_tmp12_);
						_g_free0 (_data_->_tmp12_);
						_g_error_free0 (_data_->e);
						continue;
					}
					_data_->_tmp13_ = _data_->e;
					_data_->_tmp14_ = _data_->_tmp13_->message;
					g_warning ("web.vala:363: %s", _data_->_tmp14_);
					_data_->_tmp15_ = _data_->e;
					_data_->_tmp16_ = proton_plus_utils_web_get_download_error_message (_data_->_tmp15_);
					_g_free0 (_data_->error_message);
					_data_->error_message = _data_->_tmp16_;
					_data_->result = FALSE;
					_g_error_free0 (_data_->e);
					_g_object_unref0 (_data_->file);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				__finally0:
				_g_object_unref0 (_data_->file);
				_g_free0 (_data_->error_message);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
	}
	_data_->result = FALSE;
	_g_object_unref0 (_data_->file);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

ProtonPlusUtilsWeb*
proton_plus_utils_web_construct (GType object_type)
{
	ProtonPlusUtilsWeb* self = NULL;
	self = (ProtonPlusUtilsWeb*) g_type_create_instance (object_type);
	return self;
}

ProtonPlusUtilsWeb*
proton_plus_utils_web_new (void)
{
	return proton_plus_utils_web_construct (PROTON_PLUS_UTILS_TYPE_WEB);
}

static SoupSession*
proton_plus_utils_web_get_current_session (void)
{
	SoupSession* result;
	SoupSession* _tmp0_;
	SoupSession* _tmp3_;
	_tmp0_ = proton_plus_utils_web__session;
	if (_tmp0_ == NULL) {
		SoupSession* _tmp1_;
		SoupSession* _tmp2_;
		_tmp1_ = soup_session_new ();
		_g_object_unref0 (proton_plus_utils_web__session);
		proton_plus_utils_web__session = _tmp1_;
		_tmp2_ = proton_plus_utils_web__session;
		soup_session_set_user_agent (_tmp2_, APP_NAME "/" APP_VERSION);
	}
	proton_plus_utils_web_update_proxy_settings ();
	_tmp3_ = proton_plus_utils_web__session;
	result = _tmp3_;
	return result;
}

static inline gpointer
proton_plus_utils_web_response_get_instance_private (ProtonPlusUtilsWebResponse* self)
{
	return G_STRUCT_MEMBER_P (self, ProtonPlusUtilsWebResponse_private_offset);
}

ProtonPlusUtilsWebResponse*
proton_plus_utils_web_response_construct (GType object_type)
{
	ProtonPlusUtilsWebResponse * self = NULL;
	self = (ProtonPlusUtilsWebResponse*) g_object_new (object_type, NULL);
	return self;
}

ProtonPlusUtilsWebResponse*
proton_plus_utils_web_response_new (void)
{
	return proton_plus_utils_web_response_construct (PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE);
}

ProtonPlusReturnCode
proton_plus_utils_web_response_get_code (ProtonPlusUtilsWebResponse* self)
{
	ProtonPlusReturnCode result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_code;
	return result;
}

void
proton_plus_utils_web_response_set_code (ProtonPlusUtilsWebResponse* self,
                                         ProtonPlusReturnCode value)
{
	ProtonPlusReturnCode old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_utils_web_response_get_code (self);
	if (old_value != value) {
		self->priv->_code = value;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_CODE_PROPERTY]);
	}
}

gint
proton_plus_utils_web_response_get_status_code (ProtonPlusUtilsWebResponse* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_status_code;
	return result;
}

void
proton_plus_utils_web_response_set_status_code (ProtonPlusUtilsWebResponse* self,
                                                gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_utils_web_response_get_status_code (self);
	if (old_value != value) {
		self->priv->_status_code = value;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_STATUS_CODE_PROPERTY]);
	}
}

const gchar*
proton_plus_utils_web_response_get_body (ProtonPlusUtilsWebResponse* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_body;
	result = _tmp0_;
	return result;
}

void
proton_plus_utils_web_response_set_body (ProtonPlusUtilsWebResponse* self,
                                         const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_utils_web_response_get_body (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_body);
		self->priv->_body = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_BODY_PROPERTY]);
	}
}

const gchar*
proton_plus_utils_web_response_get_error_message (ProtonPlusUtilsWebResponse* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_error_message;
	result = _tmp0_;
	return result;
}

void
proton_plus_utils_web_response_set_error_message (ProtonPlusUtilsWebResponse* self,
                                                  const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_utils_web_response_get_error_message (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_error_message);
		self->priv->_error_message = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_ERROR_MESSAGE_PROPERTY]);
	}
}

gboolean
proton_plus_utils_web_response_get_is_successful (ProtonPlusUtilsWebResponse* self)
{
	gboolean result;
	gboolean _tmp0_ = FALSE;
	gint _tmp1_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->priv->_status_code;
	if (_tmp1_ >= 200) {
		gint _tmp2_;
		_tmp2_ = self->priv->_status_code;
		_tmp0_ = _tmp2_ < 300;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static void
proton_plus_utils_web_response_class_init (ProtonPlusUtilsWebResponseClass * klass,
                                           gpointer klass_data)
{
	proton_plus_utils_web_response_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ProtonPlusUtilsWebResponse_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_proton_plus_utils_web_response_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_proton_plus_utils_web_response_set_property;
	G_OBJECT_CLASS (klass)->finalize = proton_plus_utils_web_response_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_WEB_RESPONSE_CODE_PROPERTY, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_CODE_PROPERTY] = g_param_spec_enum ("code", "code", "code", PROTON_PLUS_TYPE_RETURN_CODE, PROTON_PLUS_RETURN_CODE_REQUEST_FAILED, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_WEB_RESPONSE_STATUS_CODE_PROPERTY, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_STATUS_CODE_PROPERTY] = g_param_spec_int ("status-code", "status-code", "status-code", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_WEB_RESPONSE_BODY_PROPERTY, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_BODY_PROPERTY] = g_param_spec_string ("body", "body", "body", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_WEB_RESPONSE_ERROR_MESSAGE_PROPERTY, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_ERROR_MESSAGE_PROPERTY] = g_param_spec_string ("error-message", "error-message", "error-message", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_UTILS_WEB_RESPONSE_IS_SUCCESSFUL_PROPERTY, proton_plus_utils_web_response_properties[PROTON_PLUS_UTILS_WEB_RESPONSE_IS_SUCCESSFUL_PROPERTY] = g_param_spec_boolean ("is-successful", "is-successful", "is-successful", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
proton_plus_utils_web_response_instance_init (ProtonPlusUtilsWebResponse * self,
                                              gpointer klass)
{
	self->priv = proton_plus_utils_web_response_get_instance_private (self);
	self->priv->_code = PROTON_PLUS_RETURN_CODE_REQUEST_FAILED;
	self->priv->_status_code = 0;
	self->priv->_body = NULL;
	self->priv->_error_message = NULL;
}

static void
proton_plus_utils_web_response_finalize (GObject * obj)
{
	ProtonPlusUtilsWebResponse * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse);
	_g_free0 (self->priv->_body);
	_g_free0 (self->priv->_error_message);
	G_OBJECT_CLASS (proton_plus_utils_web_response_parent_class)->finalize (obj);
}

static GType
proton_plus_utils_web_response_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusUtilsWebResponseClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_utils_web_response_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusUtilsWebResponse), 0, (GInstanceInitFunc) proton_plus_utils_web_response_instance_init, NULL };
	GType proton_plus_utils_web_response_type_id;
	proton_plus_utils_web_response_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusUtilsWebResponse", &g_define_type_info, 0);
	ProtonPlusUtilsWebResponse_private_offset = g_type_add_instance_private (proton_plus_utils_web_response_type_id, sizeof (ProtonPlusUtilsWebResponsePrivate));
	return proton_plus_utils_web_response_type_id;
}

GType
proton_plus_utils_web_response_get_type (void)
{
	static volatile gsize proton_plus_utils_web_response_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_web_response_type_id__once)) {
		GType proton_plus_utils_web_response_type_id;
		proton_plus_utils_web_response_type_id = proton_plus_utils_web_response_get_type_once ();
		g_once_init_leave (&proton_plus_utils_web_response_type_id__once, proton_plus_utils_web_response_type_id);
	}
	return proton_plus_utils_web_response_type_id__once;
}

static void
_vala_proton_plus_utils_web_response_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec)
{
	ProtonPlusUtilsWebResponse * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse);
	switch (property_id) {
		case PROTON_PLUS_UTILS_WEB_RESPONSE_CODE_PROPERTY:
		g_value_set_enum (value, proton_plus_utils_web_response_get_code (self));
		break;
		case PROTON_PLUS_UTILS_WEB_RESPONSE_STATUS_CODE_PROPERTY:
		g_value_set_int (value, proton_plus_utils_web_response_get_status_code (self));
		break;
		case PROTON_PLUS_UTILS_WEB_RESPONSE_BODY_PROPERTY:
		g_value_set_string (value, proton_plus_utils_web_response_get_body (self));
		break;
		case PROTON_PLUS_UTILS_WEB_RESPONSE_ERROR_MESSAGE_PROPERTY:
		g_value_set_string (value, proton_plus_utils_web_response_get_error_message (self));
		break;
		case PROTON_PLUS_UTILS_WEB_RESPONSE_IS_SUCCESSFUL_PROPERTY:
		g_value_set_boolean (value, proton_plus_utils_web_response_get_is_successful (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_proton_plus_utils_web_response_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec)
{
	ProtonPlusUtilsWebResponse * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_UTILS_WEB_TYPE_RESPONSE, ProtonPlusUtilsWebResponse);
	switch (property_id) {
		case PROTON_PLUS_UTILS_WEB_RESPONSE_CODE_PROPERTY:
		proton_plus_utils_web_response_set_code (self, g_value_get_enum (value));
		break;
		case PROTON_PLUS_UTILS_WEB_RESPONSE_STATUS_CODE_PROPERTY:
		proton_plus_utils_web_response_set_status_code (self, g_value_get_int (value));
		break;
		case PROTON_PLUS_UTILS_WEB_RESPONSE_BODY_PROPERTY:
		proton_plus_utils_web_response_set_body (self, g_value_get_string (value));
		break;
		case PROTON_PLUS_UTILS_WEB_RESPONSE_ERROR_MESSAGE_PROPERTY:
		proton_plus_utils_web_response_set_error_message (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
proton_plus_utils_value_web_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
proton_plus_utils_value_web_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		proton_plus_utils_web_unref (value->data[0].v_pointer);
	}
}

static void
proton_plus_utils_value_web_copy_value (const GValue* src_value,
                                        GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = proton_plus_utils_web_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
proton_plus_utils_value_web_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
proton_plus_utils_value_web_collect_value (GValue* value,
                                           guint n_collect_values,
                                           GTypeCValue* collect_values,
                                           guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		ProtonPlusUtilsWeb * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = proton_plus_utils_web_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
proton_plus_utils_value_web_lcopy_value (const GValue* value,
                                         guint n_collect_values,
                                         GTypeCValue* collect_values,
                                         guint collect_flags)
{
	ProtonPlusUtilsWeb ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = proton_plus_utils_web_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
proton_plus_utils_param_spec_web (const gchar* name,
                                  const gchar* nick,
                                  const gchar* blurb,
                                  GType object_type,
                                  GParamFlags flags)
{
	ProtonPlusUtilsParamSpecWeb* spec;
	g_return_val_if_fail (g_type_is_a (object_type, PROTON_PLUS_UTILS_TYPE_WEB), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
proton_plus_utils_value_get_web (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PROTON_PLUS_UTILS_TYPE_WEB), NULL);
	return value->data[0].v_pointer;
}

void
proton_plus_utils_value_set_web (GValue* value,
                                 gpointer v_object)
{
	ProtonPlusUtilsWeb * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PROTON_PLUS_UTILS_TYPE_WEB));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, PROTON_PLUS_UTILS_TYPE_WEB));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		proton_plus_utils_web_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		proton_plus_utils_web_unref (old);
	}
}

void
proton_plus_utils_value_take_web (GValue* value,
                                  gpointer v_object)
{
	ProtonPlusUtilsWeb * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PROTON_PLUS_UTILS_TYPE_WEB));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, PROTON_PLUS_UTILS_TYPE_WEB));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		proton_plus_utils_web_unref (old);
	}
}

static void
proton_plus_utils_web_class_init (ProtonPlusUtilsWebClass * klass,
                                  gpointer klass_data)
{
	proton_plus_utils_web_parent_class = g_type_class_peek_parent (klass);
	((ProtonPlusUtilsWebClass *) klass)->finalize = proton_plus_utils_web_finalize;
}

static void
proton_plus_utils_web_instance_init (ProtonPlusUtilsWeb * self,
                                     gpointer klass)
{
	self->ref_count = 1;
}

static void
proton_plus_utils_web_finalize (ProtonPlusUtilsWeb * obj)
{
	ProtonPlusUtilsWeb * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_UTILS_TYPE_WEB, ProtonPlusUtilsWeb);
	g_signal_handlers_destroy (self);
}

static GType
proton_plus_utils_web_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { proton_plus_utils_value_web_init, proton_plus_utils_value_web_free_value, proton_plus_utils_value_web_copy_value, proton_plus_utils_value_web_peek_pointer, "p", proton_plus_utils_value_web_collect_value, "p", proton_plus_utils_value_web_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusUtilsWebClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_utils_web_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusUtilsWeb), 0, (GInstanceInitFunc) proton_plus_utils_web_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType proton_plus_utils_web_type_id;
	proton_plus_utils_web_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ProtonPlusUtilsWeb", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return proton_plus_utils_web_type_id;
}

GType
proton_plus_utils_web_get_type (void)
{
	static volatile gsize proton_plus_utils_web_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_web_type_id__once)) {
		GType proton_plus_utils_web_type_id;
		proton_plus_utils_web_type_id = proton_plus_utils_web_get_type_once ();
		g_once_init_leave (&proton_plus_utils_web_type_id__once, proton_plus_utils_web_type_id);
	}
	return proton_plus_utils_web_type_id__once;
}

gpointer
proton_plus_utils_web_ref (gpointer instance)
{
	ProtonPlusUtilsWeb * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
proton_plus_utils_web_unref (gpointer instance)
{
	ProtonPlusUtilsWeb * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		PROTON_PLUS_UTILS_WEB_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

