1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-30 01:55:30 +00:00

Add support for more graceful detection of HTML content

It will grab at the first fragment of the cache entry and try to detect the
content-type by looking for valid HTML. It is very stupid for now, simply
searching for "<html>", which may be bogus in certain circumstances. And I
am not sure if this is better left out and up to the scripting backends,
e.g. SMJS can now modify the cache entry.

A feable fix for bug 396.

[ From commit 3ea73da7df in ELinks
  0.12.GIT.  --KON ]
This commit is contained in:
Jonas Fonseca 2006-11-06 05:15:50 +01:00 committed by Kalle Olavi Niemitalo
parent 60dbf024e5
commit a822daef26

View File

@ -224,6 +224,34 @@ get_cache_header_content_type(struct cache_entry *cached)
return NULL;
}
unsigned char *
get_fragment_content_type(struct cache_entry *cached)
{
struct fragment *fragment;
size_t length;
unsigned char *sample;
unsigned char *ctype;
if (list_empty(cached->frag))
return NULL;
fragment = cached->frag.next;
if (fragment->offset)
return NULL;
length = fragment->length > 1024 ? 1024 : fragment->length;
sample = memacpy(fragment->data, length);
if (!sample)
return NULL;
if (strcasestr(sample, "<html>"))
ctype = stracpy("text/html");
mem_free(sample);
return ctype;
}
unsigned char *
get_content_type(struct cache_entry *cached)
{
@ -269,6 +297,12 @@ get_content_type(struct cache_entry *cached)
mem_free_if(ctype);
}
ctype = get_fragment_content_type(cached);
if (ctype && *ctype) {
cached->content_type = ctype;
return ctype;
}
debug_ctype(get_default_mime_type());
/* Fallback.. use some hardwired default */