From d235ce6180c5c82d11b95fe2dd8bf4cbe6dcb011 Mon Sep 17 00:00:00 2001 From: Jason Palmer Date: Fri, 17 Mar 2017 15:18:33 -0400 Subject: [PATCH 1/4] Do not proxy live requests --- src/cache.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cache.js b/src/cache.js index b9f9522..80dbc3c 100644 --- a/src/cache.js +++ b/src/cache.js @@ -52,6 +52,14 @@ module.exports.configure = function(mode) { protocolModule.request = function(options, callback) { var reqUrl = sepiaUtil.urlFromHttpRequestOptions(options, protocol); + var forceLive = sepiaUtil.shouldForceLive(reqUrl); + + if (forceLive) { + // Just pass thru live requests + // websocket connections fail if we proxy + return oldRequest.apply(this, arguments); + } + var reqBody = []; var debug = sepiaUtil.shouldFindMatchingFixtures(); @@ -81,8 +89,6 @@ module.exports.configure = function(mode) { options.headers = sepiaUtil.removeInternalHeaders(options.headers); - var forceLive = sepiaUtil.shouldForceLive(reqUrl); - // Only called if either the fixture with the constructed filename // exists, or we're playing back passed in data. function playback(resHeaders, resBody) { From 460f3b127679f587cbef63a7d5fb5b6f984ba8ce Mon Sep 17 00:00:00 2001 From: Jason Palmer Date: Mon, 20 Mar 2017 13:46:27 -0400 Subject: [PATCH 2/4] Do not store request in .headers file --- src/cache.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cache.js b/src/cache.js index 80dbc3c..cbeb5e6 100644 --- a/src/cache.js +++ b/src/cache.js @@ -187,10 +187,12 @@ module.exports.configure = function(mode) { var timeLength = Date.now() - startTime; headers.url = reqUrl; headers.time = timeLength; - headers.request = { - method: options.method, - headers: options.headers - }; + // Do not include the request in the header file + // it's not used and there is a separate debug option for this + // headers.request = { + // method: options.method, + // headers: sepiaUtil.parseHeaderNames(options.headers) + // }; fs.writeFileSync(filename + '.headers', JSON.stringify(headers, null, 2)); From 41228ac95d854d8ce9020f4e169e22cf642a81a8 Mon Sep 17 00:00:00 2001 From: Jason Palmer Date: Thu, 18 May 2017 11:54:28 -0400 Subject: [PATCH 3/4] Add new option to strip out gzip headers in requests --- index.js | 1 + src/cache.js | 9 +++++++++ src/util.js | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/index.js b/index.js index 895311c..a874b60 100644 --- a/index.js +++ b/index.js @@ -60,5 +60,6 @@ var sepiaUtil = require('./src/util'); module.exports.filter = sepiaUtil.addFilter; module.exports.fixtureDir = sepiaUtil.setFixtureDir; module.exports.configure = sepiaUtil.configure; +module.exports.disableGzip = sepiaUtil.disableGzip; module.exports.withSepiaServer = withSepiaServer; module.exports.shutdown = shutdown; diff --git a/src/cache.js b/src/cache.js index cbeb5e6..ad7a6b5 100644 --- a/src/cache.js +++ b/src/cache.js @@ -60,6 +60,15 @@ module.exports.configure = function(mode) { return oldRequest.apply(this, arguments); } + // Remove any gzip headers + if (sepiaUtil.gzipDisabled()) { + if (options.headers && options.headers['accept-encoding']) { + var gzipHeaders = ['gzip,deflate']; + options.headers['accept-encoding'] = options.headers['accept-encoding'] + .filter((h) => !gzipHeaders.includes(h)); + } + } + var reqBody = []; var debug = sepiaUtil.shouldFindMatchingFixtures(); diff --git a/src/util.js b/src/util.js index 34ac2bc..69ea328 100644 --- a/src/util.js +++ b/src/util.js @@ -50,6 +50,9 @@ function reset() { // These test options are set via an HTTP request to the embedded HTTP server // provided by sepia. The options are reset each time any of them are set. globalOptions.testOptions = {}; + + // Strip out gzip headers so plain text is provided + globalOptions.doNotGzip = false; } // automatically reset the state of the module when 'required'. @@ -91,6 +94,10 @@ function configure(options) { if (options.debug != null) { globalOptions.debug = options.debug; } + + if (options.doNotGzip != null) { + globalOptions.doNotGzip = options.doNotGzip; + } } // This is a commonly-used option, and thus, it should have its own function to @@ -99,6 +106,14 @@ function setFixtureDir(fixtureDir) { globalOptions.filenamePrefix = fixtureDir; } +function disableGzip() { + globalOptions.doNotGzip = true; +} + +function gzipDisabled() { + return globalOptions.doNotGzip; +} + function setTestOptions(options) { globalOptions.testOptions = {}; globalOptions.testOptions.testName = options.testName; @@ -431,6 +446,8 @@ module.exports.reset = reset; module.exports.configure = configure; module.exports.setFixtureDir = setFixtureDir; module.exports.setTestOptions = setTestOptions; +module.exports.disableGzip = disableGzip; +module.exports.gzipDisabled = gzipDisabled; module.exports.addFilter = addFilter; module.exports.constructFilename = constructFilename; module.exports.urlFromHttpRequestOptions = urlFromHttpRequestOptions; From d7877d0447f929e63f8d85cb9524e87febd9e320 Mon Sep 17 00:00:00 2001 From: Jason Palmer Date: Thu, 18 May 2017 14:39:14 -0400 Subject: [PATCH 4/4] Bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cec7fd8..59de83d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sepia", "author": "Avik Das ", - "version": "2.0.1", + "version": "2.0.4", "description": "A VCR-like module that records HTTP interactions and plays them back for speed and reliability", "keywords": [ "http",