Explorar o código

Improve JSON detection when the mime-type is not application/json

Gaël Métais %!s(int64=4) %!d(string=hai) anos
pai
achega
6d01461e53
Modificáronse 2 ficheiros con 18 adicións e 3 borrados
  1. 16 2
      lib/tools/redownload/contentTypeChecker.js
  2. 2 1
      package.json

+ 16 - 2
lib/tools/redownload/contentTypeChecker.js

@@ -10,6 +10,7 @@ var isWoff2 = require('is-woff2');
 var isOtf   = require('is-otf');
 var isOtf   = require('is-otf');
 var isTtf   = require('is-ttf');
 var isTtf   = require('is-ttf');
 var isEot   = require('is-eot');
 var isEot   = require('is-eot');
+var isJson  = require('is-json');
 
 
 var ContentTypeChecker = function() {
 var ContentTypeChecker = function() {
 
 
@@ -57,7 +58,7 @@ var ContentTypeChecker = function() {
                 foundType = findContentType(entry.weightCheck.bodyBuffer);
                 foundType = findContentType(entry.weightCheck.bodyBuffer);
 
 
                 // If it's an image or a font, then rewrite.
                 // If it's an image or a font, then rewrite.
-                if (foundType !== null && (foundType.type === 'image' || foundType.type === 'webfont')) {
+                if (foundType !== null && (foundType.type === 'image' || foundType.type === 'webfont' || foundType.type === 'json')) {
                     if (foundType.type !== entry.type) {
                     if (foundType.type !== entry.type) {
                         debug('Content type %s is wrong for %s. It should be %s.', entry.type, entry.ulr, foundType.type);
                         debug('Content type %s is wrong for %s. It should be %s.', entry.type, entry.ulr, foundType.type);
                     }
                     }
@@ -119,6 +120,10 @@ var ContentTypeChecker = function() {
             return contentTypes.eot;
             return contentTypes.eot;
         }
         }
 
 
+        if (isJson(bodyStr)) {
+            return contentTypes.json;
+        }
+
         return null;
         return null;
     }
     }
 
 
@@ -224,7 +229,16 @@ var ContentTypeChecker = function() {
                 entry.type = 'webfont';
                 entry.type = 'webfont';
                 entry.isWebFont = true;
                 entry.isWebFont = true;
             }
             }
-        }
+        },
+        json: {
+            type: 'json',
+            mimes: ['application/json'],
+            updateFn: function(entry) {
+                entry.type = 'json';
+                entry.isJSON = true;
+            }
+        },
+        
     };
     };
     
     
     return {
     return {

+ 2 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "yellowlabtools",
   "name": "yellowlabtools",
-  "version": "2.0.0-beta",
+  "version": "2.0.0",
   "description": "Online tool to audit a webpage for performance and front-end quality issues",
   "description": "Online tool to audit a webpage for performance and front-end quality issues",
   "license": "GPL-2.0",
   "license": "GPL-2.0",
   "author": {
   "author": {
@@ -50,6 +50,7 @@
     "is-eot": "1.0.0",
     "is-eot": "1.0.0",
     "is-gif": "3.0.0",
     "is-gif": "3.0.0",
     "is-jpg": "2.0.0",
     "is-jpg": "2.0.0",
+    "is-json": "2.0.1",
     "is-otf": "0.1.2",
     "is-otf": "0.1.2",
     "is-png": "1.1.0",
     "is-png": "1.1.0",
     "is-svg": "3.0.0",
     "is-svg": "3.0.0",