summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2020-01-06 04:00:52 +0300
committerdefanor <defanor@uberspace.net>2020-01-06 04:00:52 +0300
commite35ff9bcddd7819b5110cfeb9acf2e727063090e (patch)
tree603c3f9eecbabf6f53d389e625a165be1d7be67d
parente4e0a7850b6e1bdd8c6405e85bec0243cf7027c8 (diff)
downloadwwwlite-e35ff9bcddd7819b5110cfeb9acf2e727063090e.zip
wwwlite-e35ff9bcddd7819b5110cfeb9acf2e727063090e.tar.gz
wwwlite-e35ff9bcddd7819b5110cfeb9acf2e727063090e.tar.bz2
Check web page headers
Don't try to render non-(X)HTML documents.
-rw-r--r--src/browserbox.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/browserbox.c b/src/browserbox.c
index dd3a043..595afb3 100644
--- a/src/browserbox.c
+++ b/src/browserbox.c
@@ -1296,7 +1296,6 @@ void got_headers(SoupMessage *msg, gpointer ptr)
{
BrowserBox *bb = ptr;
browser_box_set_status(bb, "Got headers");
- /* todo: check content type, don't assume HTML */
if (bb->builder_state != NULL) {
if (bb->builder_state->docbox != NULL) {
gtk_widget_destroy(GTK_WIDGET(bb->builder_state->docbox));
@@ -1308,6 +1307,18 @@ void got_headers(SoupMessage *msg, gpointer ptr)
char *uri_str = soup_uri_to_string(bb->builder_state->uri, FALSE);
gtk_entry_set_text(GTK_ENTRY(bb->address_bar), uri_str);
free(uri_str);
+
+ SoupMessageHeaders *smh;
+ g_object_get(msg,
+ "response-headers", &smh,
+ NULL);
+ const char *ct = soup_message_headers_get_content_type(smh, NULL);
+ if (! (strcmp(ct, "text/html") == 0 ||
+ strcmp(ct, "application/xhtml+xml") == 0)) {
+ browser_box_set_status(bb, "Unsupported content type");
+ /* todo: offer to download a file */
+ bb->builder_state->active = FALSE;
+ }
}
void document_request_sm (BrowserBox *bb, SoupMessage *sm)