If proxy is set then use http proxy.
---
gweb/gweb.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 63 insertions(+), 1 deletions(-)
diff --git a/gweb/gweb.c b/gweb/gweb.c
index a348cdd..b041a3e 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -59,6 +59,7 @@ struct web_session {
char *address;
char *host;
+ char *host_request;
uint16_t port;
unsigned long flags;
@@ -154,6 +155,7 @@ static void free_session(struct web_session *session)
g_free(session->content_type);
+ g_free(session->host_request);
g_free(session->host);
g_free(session->address);
g_free(session);
@@ -455,7 +457,7 @@ static void start_request(struct web_session *session)
g_string_append_printf(buf, "POST %s HTTP/%s\r\n",
session->request, version);
- g_string_append_printf(buf, "Host: %s\r\n", session->host);
+ g_string_append_printf(buf, "Host: %s\r\n", session->host_request);
if (session->web->user_agent != NULL)
g_string_append_printf(buf, "User-Agent: %s\r\n",
@@ -859,6 +861,59 @@ static int parse_url(struct web_session *session, const
char *url)
session->request = g_strdup_printf("/%s", path ? path : "");
+ session->host_request = g_strdup(host);
+
+ port = strrchr(host, ':');
+ if (port != NULL) {
+ char *end;
+ int tmp = strtol(port + 1, &end, 10);
+
+ if (*end == '\0') {
+ *port = '\0';
+ session->port = tmp;
+ }
+ }
+
+ session->host = g_strdup(host);
+
+ g_free(scheme);
+
+ return 0;
+}
+
+static int parse_proxy_url(struct web_session *session, const char *proxy,
+ const char *url)
+{
+ char *scheme, *host, *port;
+
+ if (session->web == NULL)
+ return -EINVAL;
+
+ session->flags &= ~SESSION_FLAG_USE_TLS;
+
+ scheme = g_strdup(proxy);
+ if (scheme == NULL)
+ return -EINVAL;
+
+ host = strstr(scheme, "://");
+ if (host != NULL) {
+ *host = '\0';
+ host += 3;
+
+ if (strcasecmp(scheme, "https") == 0) {
+ session->port = 443;
+ session->flags |= SESSION_FLAG_USE_TLS;
+ } else if (strcasecmp(scheme, "http") == 0) {
+ session->port = 80;
+ } else {
+ g_free(scheme);
+ return -EINVAL;
+ }
+ } else {
+ host = scheme;
+ session->port = 80;
+ }
+
port = strrchr(host, ':');
if (port != NULL) {
char *end;
@@ -870,8 +925,12 @@ static int parse_url(struct web_session *session, const
char *url)
}
}
+ g_free(session->host);
session->host = g_strdup(host);
+ g_free(session->request);
+ session->request = g_strdup(url);
+
g_free(scheme);
return 0;
@@ -949,6 +1008,9 @@ static guint do_request(GWeb *web, const char *url,
session->header_done = FALSE;
session->body_done = FALSE;
+ if (web->proxy != NULL)
+ parse_proxy_url(session, web->proxy, url);
+
if (inet_aton(session->host, NULL) == 0) {
session->resolv_action = g_resolv_lookup_hostname(web->resolv,
session->host, resolv_result, session);
--
1.7.2.3
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman