From 3e2e110a86f53b391fb2d6f20487e7510de4336c Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 8 Feb 2012 00:52:16 +0000 Subject: Bypass full type sniffer if only images are acceptable svn path=/trunk/netsurf/; revision=13436 --- content/hlcache.c | 4 +++- content/mimesniff.c | 21 ++++++++++++++++++++- content/mimesniff.h | 3 ++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/content/hlcache.c b/content/hlcache.c index c7a803dee..a22162f50 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -522,6 +522,7 @@ nserror hlcache_llcache_callback(llcache_handle *handle, case LLCACHE_EVENT_HAD_HEADERS: error = mimesniff_compute_effective_type(handle, NULL, 0, ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE, + ctx->accepted_types == CONTENT_IMAGE, &effective_type); if (error == NSERROR_OK || error == NSERROR_NOT_FOUND) { /* If the sniffer was successful or failed to find @@ -545,6 +546,7 @@ nserror hlcache_llcache_callback(llcache_handle *handle, error = mimesniff_compute_effective_type(handle, event->data.data.buf, event->data.data.len, ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE, + ctx->accepted_types == CONTENT_IMAGE, &effective_type); if (error != NSERROR_OK) { assert(0 && "MIME sniff failed with data"); @@ -561,7 +563,7 @@ nserror hlcache_llcache_callback(llcache_handle *handle, /* DONE event before we could determine the effective MIME type. */ error = mimesniff_compute_effective_type(handle, - NULL, 0, false, &effective_type); + NULL, 0, false, false, &effective_type); if (error == NSERROR_OK) { error = hlcache_migrate_ctx(ctx, effective_type); diff --git a/content/mimesniff.c b/content/mimesniff.c index 62dfb02bb..5b2c14fb5 100644 --- a/content/mimesniff.c +++ b/content/mimesniff.c @@ -62,6 +62,7 @@ static lwc_string *application_x_gzip; static lwc_string *application_postscript; static lwc_string *application_pdf; static lwc_string *video_mp4; +static lwc_string *image_svg; nserror mimesniff_init(void) { @@ -97,6 +98,7 @@ nserror mimesniff_init(void) SINIT(application_postscript, "application/postscript"); SINIT(application_pdf, "application/pdf"); SINIT(video_mp4, "video/mp4"); + SINIT(image_svg, "image/svg+xml"); #undef SINIT return NSERROR_OK; @@ -104,6 +106,7 @@ nserror mimesniff_init(void) void mimesniff_fini(void) { + lwc_string_unref(image_svg); lwc_string_unref(video_mp4); lwc_string_unref(application_pdf); lwc_string_unref(application_postscript); @@ -636,7 +639,7 @@ static nserror mimesniff__compute_feed_or_html(const uint8_t *data, /* See mimesniff.h for documentation */ nserror mimesniff_compute_effective_type(llcache_handle *handle, const uint8_t *data, size_t len, bool sniff_allowed, - lwc_string **effective_type) + bool image_only, lwc_string **effective_type) { #define S(s) { s, SLEN(s) } static const struct tt_s { @@ -683,6 +686,22 @@ nserror mimesniff_compute_effective_type(llcache_handle *handle, return NSERROR_OK; } + if (image_only) { + lwc_string *official_type; + + if (lwc_string_caseless_isequal(ct->media_type, image_svg, + &match) == lwc_error_ok && match) { + *effective_type = lwc_string_ref(image_svg); + http_content_type_destroy(ct); + return NSERROR_OK; + } + + official_type = lwc_string_ref(ct->media_type); + http_content_type_destroy(ct); + return mimesniff__compute_image(official_type, + data, len, effective_type); + } + content_type_header_len = strlen(content_type_header); /* Look for text types */ diff --git a/content/mimesniff.h b/content/mimesniff.h index 331adc28c..bf3e493f3 100644 --- a/content/mimesniff.h +++ b/content/mimesniff.h @@ -38,6 +38,7 @@ struct llcache_handle; * \param data First data chunk, or NULL * \param len Length of \a data, in bytes * \param sniff_allowed Whether MIME type sniffing is allowed + * \param image_only Sniff image types only * \param effective_type Location to receive computed type * \return NSERROR_OK on success, * NSERROR_NEED_DATA iff \a data is NULL and data is needed @@ -46,7 +47,7 @@ struct llcache_handle; */ nserror mimesniff_compute_effective_type(struct llcache_handle *handle, const uint8_t *data, size_t len, bool sniff_allowed, - lwc_string **effective_type); + bool image_only, lwc_string **effective_type); nserror mimesniff_init(void); void mimesniff_fini(void); -- cgit v1.2.3