Fix content type checking after switching to phantomas v2
This commit is contained in:
@@ -17,6 +17,7 @@ var ContentTypeChecker = function() {
|
||||
var deferred = Q.defer();
|
||||
|
||||
debug('Entering contentTypeChecker');
|
||||
debug(entry);
|
||||
|
||||
// Setting isSomething values:
|
||||
switch(entry.type) {
|
||||
@@ -57,24 +58,10 @@ var ContentTypeChecker = function() {
|
||||
|
||||
try {
|
||||
foundType = findContentType(entry.weightCheck.bodyBuffer);
|
||||
|
||||
// Note: as of Phantomas v2, entry.contentType is always undefined
|
||||
// It could change, so let's keep the following code in place:
|
||||
|
||||
if (!entry.contentType || entry.contentType === '') {
|
||||
if (foundType === null) {
|
||||
debug('ContentType is empty for file %s', entry.url);
|
||||
} else {
|
||||
debug('ContentType is empty for file %s. It should be %s.', entry.url, foundType.mimes[0]);
|
||||
entry.oldContentType = null;
|
||||
rewriteContentType(entry, foundType);
|
||||
}
|
||||
} else {
|
||||
if (foundType !== null && foundType.mimes.indexOf(entry.contentType) === -1) {
|
||||
debug('ContentType %s is wrong for %s. It should be %s.', entry.contentType, entry.url, foundType.mimes[0]);
|
||||
entry.oldContentType = entry.contentType;
|
||||
rewriteContentType(entry, foundType);
|
||||
}
|
||||
if (foundType !== null && foundType.type !== entry.type) {
|
||||
debug('Content type %s is wrong for %s. It should be %s.', entry.type, entry.ulr, foundType.type);
|
||||
rewriteContentType(entry, foundType);
|
||||
}
|
||||
|
||||
} catch(err) {
|
||||
@@ -155,6 +142,7 @@ var ContentTypeChecker = function() {
|
||||
|
||||
var contentTypes = {
|
||||
jpeg: {
|
||||
type: 'image',
|
||||
mimes: ['image/jpeg'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'image';
|
||||
@@ -162,6 +150,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
png: {
|
||||
type: 'image',
|
||||
mimes: ['image/png'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'image';
|
||||
@@ -169,6 +158,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
svg: {
|
||||
type: 'image',
|
||||
mimes: ['image/svg+xml'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'image';
|
||||
@@ -177,6 +167,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
gif: {
|
||||
type: 'image',
|
||||
mimes: ['image/gif'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'image';
|
||||
@@ -184,6 +175,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
webp: {
|
||||
type: 'image',
|
||||
mimes: ['image/webp'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'image';
|
||||
@@ -191,6 +183,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
woff: {
|
||||
type: 'webfont',
|
||||
mimes: ['application/x-font-woff', 'application/font-woff', 'font/woff'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'webfont';
|
||||
@@ -198,6 +191,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
woff2: {
|
||||
type: 'webfont',
|
||||
mimes: ['font/woff2', 'application/x-font-woff2', 'application/font-woff2'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'webfont';
|
||||
@@ -205,6 +199,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
otf: {
|
||||
type: 'webfont',
|
||||
mimes: ['application/x-font-otf', 'font/otf', 'font/opentype', 'application/x-font-opentype'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'webfont';
|
||||
@@ -212,6 +207,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
ttf: {
|
||||
type: 'webfont',
|
||||
mimes: ['application/x-font-ttf', 'font/ttf', 'application/x-font-truetype'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'webfont';
|
||||
@@ -219,6 +215,7 @@ var ContentTypeChecker = function() {
|
||||
}
|
||||
},
|
||||
eot: {
|
||||
type: 'webfont',
|
||||
mimes: ['application/vnd.ms-fontobject', 'font/eot'],
|
||||
updateFn: function(entry) {
|
||||
entry.type = 'webfont';
|
||||
|
||||
Reference in New Issue
Block a user