-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow option to disable gzip compression with a flag (gzipEnable: false) gzip compression still remains enabled by default fixes #196
- Loading branch information
Showing
3 changed files
with
68 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
debug = require('debug')('spec-integration:products') | ||
_ = require 'underscore' | ||
Promise = require 'bluebird' | ||
{SphereClient} = require '../../lib/main' | ||
Config = require('../../config').config | ||
|
||
newProductType = -> | ||
name: 'Vehicle' | ||
description: 'A sample type of vehicle' | ||
|
||
describe 'gzip compression', -> | ||
|
||
afterEach (done) -> | ||
debug 'About to delete all product types' | ||
@client.productTypes.all().fetch() | ||
.then (payload) => | ||
debug "Deleting #{payload.body.total} product types" | ||
Promise.all _.map payload.body.results, (productType) => | ||
@client.productTypes.byId(productType.id).delete(productType.version) | ||
.then (results) -> | ||
debug "Deleted #{results.length} product types" | ||
done() | ||
.catch (error) -> done(_.prettify(error)) | ||
, 20000 # 20 sec | ||
|
||
it 'should use gzip compression by default for all requests', (done) -> | ||
@client = new SphereClient | ||
config: Config | ||
stats: | ||
includeHeaders: true | ||
debug 'Creating a ProductType' | ||
@client.productTypes.save(newProductType()) | ||
.then (result) => | ||
expect(result.statusCode).toBe 201 | ||
@client.productTypes.fetch() | ||
.then (results) -> | ||
gzipReqHeader = results.http.request.headers['accept-encoding'] | ||
gzipResHeader = results.http.response.headers['content-encoding'] | ||
expect(gzipReqHeader).toBeTruthy() | ||
expect(gzipReqHeader).toBe 'gzip' | ||
expect(gzipResHeader).toBeTruthy() | ||
expect(gzipResHeader).toBe 'gzip' | ||
done() | ||
.catch (error) -> done(_.prettify(error)) | ||
, 20000 # 20 sec | ||
|
||
it 'should not use gzip compression when disbled', (done) -> | ||
@client = new SphereClient | ||
config: Config | ||
stats: | ||
includeHeaders: true | ||
gzipEnable: false | ||
debug 'Creating a ProductType' | ||
@client.productTypes.save(newProductType()) | ||
.then (result) => | ||
expect(result.statusCode).toBe 201 | ||
@client.productTypes.fetch() | ||
.then (results) -> | ||
gzipReqHeader = results.http.request.headers['accept-encoding'] | ||
gzipResHeader = results.http.response.headers['content-encoding'] | ||
expect(gzipReqHeader).not.toBeDefined() | ||
expect(gzipResHeader).not.toBeDefined() | ||
done() | ||
.catch (error) -> done(_.prettify(error)) | ||
, 20000 # 20 sec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters