+ if (proxy == NULL)
+ session->request = g_strdup_printf("/%s", path ? path : "");
+ else
+ session->request = g_strdup(url);
+
+ port = strrchr(host, ':');
+ if (port != NULL) {
+ char *end;
+ int tmp = strtol(port + 1, &end, 10);
+
+ if (*end == '\0') {
+ *port = '\0';
+ session->port = tmp;
+ }
+
+ if (proxy == NULL)
+ session->host = g_strdup(host);
+ else
+ session->host = g_strdup_printf("%s:%u", host, tmp);
+ } else
+ session->host = g_strdup(host);
+
+ g_free(scheme);
+
+ if (proxy == NULL)
+ return 0;
+
+ scheme = g_strdup(proxy);
+ if (scheme == NULL)
+ return -EINVAL;
+
+ host = strstr(proxy, "://");
+ if (host != NULL) {
+ *host = '\0';
+ host += 3;
+
+ if (strcasecmp(scheme, "http") != 0) {
+ g_free(scheme);
+ return -EINVAL;
+ }
+ } else
+ host = scheme;
+
+ path = strchr(host, '/');
+ if (path != NULL)
+ *(path++) = '\0';