surf

Surf web browser.
git clone git://r-36.net/surf
Log | Files | Refs | README | LICENSE

commit 70b1126a710fd0fff9cc9c63ba81645e2ac21eae
parent ee7bf0c1b8e86154a30baa94a90c05f21d3d9f58
Author: Christoph Lohmann <20h@r-36.net>
Date:   Wed, 19 Apr 2017 21:10:23 +0200

Allow custom http headers to be specified.

Diffstat:
config.def.h | 6++++++
surf.c | 36+++++++++++++++++++++++++++++-------
2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -37,6 +37,12 @@ static Bool loadimages = TRUE; static Bool hidebackground = FALSE; static Bool allowgeolocation = TRUE; +/* custom http headers */ +static HttpHeader customheaders[] = { + /* key value */ + { "DNT", "1" }, +}; + #define PROMPT_GOTO "Go To" #define PROMPT_FIND "Find" #define PROMPT_SLASH "/" diff --git a/surf.c b/surf.c @@ -66,6 +66,11 @@ typedef struct Client { } Client; typedef struct { + char *key; + char *value; +} HttpHeader; + +typedef struct { guint mod; guint keyval; void (*func)(Client *c, const Arg *arg); @@ -243,6 +248,8 @@ beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, WebKitNetworkRequest *req, WebKitNetworkResponse *resp, Client *c) { + SoupMessage *msg; + SoupMessageHeaders *hdrs; const gchar *uri = webkit_network_request_get_uri(req); int i, isascii = 1; @@ -250,12 +257,12 @@ beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, webkit_network_request_set_uri(req, "about:blank"); if (!g_str_has_prefix(uri, "http://") - && !g_str_has_prefix(uri, "https://") - && !g_str_has_prefix(uri, "about:") - && !g_str_has_prefix(uri, "file://") - && !g_str_has_prefix(uri, "data:") - && !g_str_has_prefix(uri, "blob:") - && strlen(uri) > 0) { + && !g_str_has_prefix(uri, "https://") + && !g_str_has_prefix(uri, "about:") + && !g_str_has_prefix(uri, "file://") + && !g_str_has_prefix(uri, "data:") + && !g_str_has_prefix(uri, "blob:") + && strlen(uri) > 0) { for (i = 0; i < strlen(uri); i++) { if (!g_ascii_isprint(uri[i])) { isascii = 0; @@ -264,6 +271,21 @@ beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, } if (isascii) handleplumb(c, w, uri); + + return; + } + if (g_str_has_prefix(uri, "http://") + || g_str_has_prefix(uri, "https://")) { + msg = webkit_network_request_get_message(req); + g_object_get(G_OBJECT(msg), "request-headers", &hdrs, + NULL); + if (hdrs != NULL) { + for (i = 0; i < LENGTH(customheaders); i++) { + soup_message_headers_replace(hdrs, + customheaders[i].key, + customheaders[i].value); + } + } } } @@ -882,6 +904,7 @@ loaduri(Client *c, const Arg *arg) setatom(c, AtomUri, uri); + /* prevents endless loop */ if (strcmp(u, geturi(c)) == 0) { reload(c, &a); @@ -1399,7 +1422,6 @@ setup(void) /* ssl */ tlsdb = g_tls_file_database_new(cafile, &error); - if (error) { g_warning("Error loading SSL database %s: %s", cafile, error->message);