mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 12:12:35 +03:00
Bypass full type sniffer if only images are acceptable
svn path=/trunk/netsurf/; revision=13436
This commit is contained in:
parent
e2bb4aa4e0
commit
3e2e110a86
@ -522,6 +522,7 @@ nserror hlcache_llcache_callback(llcache_handle *handle,
|
|||||||
case LLCACHE_EVENT_HAD_HEADERS:
|
case LLCACHE_EVENT_HAD_HEADERS:
|
||||||
error = mimesniff_compute_effective_type(handle, NULL, 0,
|
error = mimesniff_compute_effective_type(handle, NULL, 0,
|
||||||
ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE,
|
ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE,
|
||||||
|
ctx->accepted_types == CONTENT_IMAGE,
|
||||||
&effective_type);
|
&effective_type);
|
||||||
if (error == NSERROR_OK || error == NSERROR_NOT_FOUND) {
|
if (error == NSERROR_OK || error == NSERROR_NOT_FOUND) {
|
||||||
/* If the sniffer was successful or failed to find
|
/* 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,
|
error = mimesniff_compute_effective_type(handle,
|
||||||
event->data.data.buf, event->data.data.len,
|
event->data.data.buf, event->data.data.len,
|
||||||
ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE,
|
ctx->flags & HLCACHE_RETRIEVE_SNIFF_TYPE,
|
||||||
|
ctx->accepted_types == CONTENT_IMAGE,
|
||||||
&effective_type);
|
&effective_type);
|
||||||
if (error != NSERROR_OK) {
|
if (error != NSERROR_OK) {
|
||||||
assert(0 && "MIME sniff failed with data");
|
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.
|
/* DONE event before we could determine the effective MIME type.
|
||||||
*/
|
*/
|
||||||
error = mimesniff_compute_effective_type(handle,
|
error = mimesniff_compute_effective_type(handle,
|
||||||
NULL, 0, false, &effective_type);
|
NULL, 0, false, false, &effective_type);
|
||||||
if (error == NSERROR_OK) {
|
if (error == NSERROR_OK) {
|
||||||
error = hlcache_migrate_ctx(ctx, effective_type);
|
error = hlcache_migrate_ctx(ctx, effective_type);
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ static lwc_string *application_x_gzip;
|
|||||||
static lwc_string *application_postscript;
|
static lwc_string *application_postscript;
|
||||||
static lwc_string *application_pdf;
|
static lwc_string *application_pdf;
|
||||||
static lwc_string *video_mp4;
|
static lwc_string *video_mp4;
|
||||||
|
static lwc_string *image_svg;
|
||||||
|
|
||||||
nserror mimesniff_init(void)
|
nserror mimesniff_init(void)
|
||||||
{
|
{
|
||||||
@ -97,6 +98,7 @@ nserror mimesniff_init(void)
|
|||||||
SINIT(application_postscript, "application/postscript");
|
SINIT(application_postscript, "application/postscript");
|
||||||
SINIT(application_pdf, "application/pdf");
|
SINIT(application_pdf, "application/pdf");
|
||||||
SINIT(video_mp4, "video/mp4");
|
SINIT(video_mp4, "video/mp4");
|
||||||
|
SINIT(image_svg, "image/svg+xml");
|
||||||
#undef SINIT
|
#undef SINIT
|
||||||
|
|
||||||
return NSERROR_OK;
|
return NSERROR_OK;
|
||||||
@ -104,6 +106,7 @@ nserror mimesniff_init(void)
|
|||||||
|
|
||||||
void mimesniff_fini(void)
|
void mimesniff_fini(void)
|
||||||
{
|
{
|
||||||
|
lwc_string_unref(image_svg);
|
||||||
lwc_string_unref(video_mp4);
|
lwc_string_unref(video_mp4);
|
||||||
lwc_string_unref(application_pdf);
|
lwc_string_unref(application_pdf);
|
||||||
lwc_string_unref(application_postscript);
|
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 */
|
/* See mimesniff.h for documentation */
|
||||||
nserror mimesniff_compute_effective_type(llcache_handle *handle,
|
nserror mimesniff_compute_effective_type(llcache_handle *handle,
|
||||||
const uint8_t *data, size_t len, bool sniff_allowed,
|
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) }
|
#define S(s) { s, SLEN(s) }
|
||||||
static const struct tt_s {
|
static const struct tt_s {
|
||||||
@ -683,6 +686,22 @@ nserror mimesniff_compute_effective_type(llcache_handle *handle,
|
|||||||
return NSERROR_OK;
|
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);
|
content_type_header_len = strlen(content_type_header);
|
||||||
|
|
||||||
/* Look for text types */
|
/* Look for text types */
|
||||||
|
@ -38,6 +38,7 @@ struct llcache_handle;
|
|||||||
* \param data First data chunk, or NULL
|
* \param data First data chunk, or NULL
|
||||||
* \param len Length of \a data, in bytes
|
* \param len Length of \a data, in bytes
|
||||||
* \param sniff_allowed Whether MIME type sniffing is allowed
|
* \param sniff_allowed Whether MIME type sniffing is allowed
|
||||||
|
* \param image_only Sniff image types only
|
||||||
* \param effective_type Location to receive computed type
|
* \param effective_type Location to receive computed type
|
||||||
* \return NSERROR_OK on success,
|
* \return NSERROR_OK on success,
|
||||||
* NSERROR_NEED_DATA iff \a data is NULL and data is needed
|
* 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,
|
nserror mimesniff_compute_effective_type(struct llcache_handle *handle,
|
||||||
const uint8_t *data, size_t len, bool sniff_allowed,
|
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);
|
nserror mimesniff_init(void);
|
||||||
void mimesniff_fini(void);
|
void mimesniff_fini(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user