From 0275003c4c08eb2907fefd58a40252b955f42a05 Mon Sep 17 00:00:00 2001 From: Martii Date: Wed, 9 Mar 2016 15:39:03 -0700 Subject: [PATCH] Set up a `Warning` header for minification failure * New dep *rfc2047* to allow external viewing of *UglifyJS2* message warning via header... this one appears to follow the spec as closely as possible unlike some others * No known guarantee that `message`s from *UglifyJS2* will be ISO-8859-1 so Q encode under RFC2047 * Since it is MIME format typically this should be wrapped at 76 characters... however *express*/*node* throws an exception... current deviation from the spec * *express* currently only handles one `Warning` header which isn't to spec as well... see http://expressjs.com/en/api.html#res.set * *node* currently only handles one `Warning` header which isn't spec as well... see https://nodejs.org/api/http.html#http_response_setheader_name_value * *express* should be sending HTTP/1.1 so no matching date should be required for compliance as per spec Ref: * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46 Applies to #432 --- README.md | 6 ++++++ controllers/scriptStorage.js | 12 ++++++++++++ package.json | 1 + 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 50284cbf7..bce73079b 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Repository | Reference | Recent Version [passport-yahoo][passport-yahooGHUrl] | [Documentation][passport-yahooDOCUrl] | [![NPM version][passport-yahooNPMVersionImage]][passport-yahooNPMUrl] [pegjs][pegjsGHUrl] | [Documentation][pegjsDOCUrl] | [![NPM version][pegjsNPMVersionImage]][pegjsNPMUrl] [request][requestGHUrl] | [Documentation][requestDOCUrl] | [![NPM version][requestNPMVersionImage]][requestNPMUrl] +[rfc2047][rfc2047GHUrl] | [Documentation][rfc2047DOCUrl] | [![NPM version][rfc2047NPMVersionImage]][rfc2047NPMUrl] [sanitize-html][sanitize-htmlGHUrl] | [Documentation][sanitize-htmlDOCUrl] | [![NPM version][sanitize-htmlNPMVersionImage]][sanitize-htmlNPMUrl] [select2][select2GHUrl] | [Documentation][select2DOCUrl] | [![NPM version][select2NPMVersionImage]][select2NPMUrl] [select2-bootstrap-css][select2-bootstrap-cssGHUrl] | [Documentation][select2-bootstrap-cssDOCUrl] | [![NPM version][select2-bootstrap-cssNPMVersionImage]][select2-bootstrap-cssNPMUrl] @@ -376,6 +377,11 @@ Outdated dependencies list can also be achieved with `$ npm --depth 0 outdated` [requestNPMUrl]: https://www.npmjs.com/package/request [requestNPMVersionImage]: https://img.shields.io/npm/v/request.svg?style=flat +[rfc2047GHUrl]: https://github.com/One-com/rfc2047 +[rfc2047DOCUrl]: https://github.com/One-com/rfc2047/blob/master/README.md +[rfc2047NPMUrl]: https://www.npmjs.com/package/rfc2047 +[rfc2047NPMVersionImage]: https://img.shields.io/npm/v/rfc2047.svg?style=flat + [sanitize-htmlGHUrl]: https://github.com/punkave/sanitize-html [sanitize-htmlDOCUrl]: https://github.com/punkave/sanitize-html/blob/master/README.md [sanitize-htmlNPMUrl]: https://www.npmjs.com/package/sanitize-html diff --git a/controllers/scriptStorage.js b/controllers/scriptStorage.js index 2bde107b7..f343aca11 100644 --- a/controllers/scriptStorage.js +++ b/controllers/scriptStorage.js @@ -12,6 +12,7 @@ var fs = require('fs'); var PEG = require('pegjs'); var AWS = require('aws-sdk'); var UglifyJS = require("uglify-js-harmony"); +var rfc2047 = require('rfc2047'); //--- Model inclusions var Script = require('../models/script').Script; @@ -238,6 +239,7 @@ exports.sendScript = function (aReq, aRes, aNext) { aStream.on('end', function () { var source = chunks.join(''); // NOTE: Watchpoint + var msg = null; try { source = UglifyJS.minify(source, { @@ -260,6 +262,16 @@ exports.sendScript = function (aReq, aRes, aNext) { ].join('\n')); + // Set up a `Warning` header with Q encoding under RFC2047 + msg = [ + '199 ' + aReq.headers.host + ' MINIFICATION WARNING (harmony):', + ' ' + rfc2047.encode(aE.message), + ' line: ' + aE.line + ' col: ' + aE.col + ' pos: ' + aE.pos + + ].join('\u0020'); // TODO: Watchpoint... *express*/*node* exception thrown with CRLF SPACE spec + + + aRes.set('Warning', msg); } aRes.write(source); diff --git a/package.json b/package.json index cdb278425..cd30e8cd3 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "passport-yahoo": "0.3.0", "pegjs": "0.9.0", "request": "2.69.0", + "rfc2047": "2.0.0", "sanitize-html": "1.11.3", "select2": "3.5.2-browserify", "select2-bootstrap-css": "1.4.6",