Skip to content

Commit e0bd86e

Browse files
committed
fix: default contentEncodings and contentTypes to constants
closes #373
1 parent d50b7e7 commit e0bd86e

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/configure.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ const { getEventSourceNameBasedOnEvent } = require('./event-sources/utils')
66
const { getFramework } = require('./frameworks')
77
const makeResolver = require('./make-resolver')
88
const { forwardRequestToNodeServer, respondToEventSourceWithError } = require('./transport')
9-
10-
const DEFAULT_BINARY_ENCODINGS = ['gzip', 'deflate', 'br']
11-
const DEFAULT_BINARY_CONTENT_TYPES = ['image/*']
9+
const { DEFAULT_BINARY_ENCODINGS, DEFAULT_BINARY_CONTENT_TYPES } = require('./constants')
1210

1311
function getDefaultBinarySettings (deprecatedBinaryMimeTypes) {
1412
return {

src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module.exports.DEFAULT_BINARY_ENCODINGS = ['gzip', 'deflate', 'br']
2+
module.exports.DEFAULT_BINARY_CONTENT_TYPES = ['image/*']

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ function createServer (app, serverListenCallback, binaryMimeTypes) {
2525
}
2626

2727
function proxy (configureOptions, event, context, resolutionMode, callback) {
28+
console.warn('[DEPRECATION NOTICE] You\'re using the deprecated proxy method that will be removed in the next major version. See https://github.com/vendia/serverless-express/blob/mainline/UPGRADE.md to upgrade.')
29+
2830
const se = configure({
2931
...configureOptions,
3032
resolutionMode
3133
})
3234
return se(event, context, callback)
3335
}
36+
3437
module.exports.createServer = createServer
3538
module.exports.proxy = proxy

src/is-binary.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ATTRIBUTION: https://github.com/dougmoscrop/serverless-http
2+
const { DEFAULT_BINARY_ENCODINGS, DEFAULT_BINARY_CONTENT_TYPES } = require('./constants')
23

34
function isContentEncodingBinary ({ headers, binaryEncodingTypes }) {
45
const contentEncoding = headers['content-encoding']
@@ -37,6 +38,9 @@ module.exports = function isBinary ({ headers, binarySettings }) {
3738
return binarySettings.isBinary({ headers })
3839
}
3940

40-
return isContentEncodingBinary({ headers, binaryEncodingTypes: binarySettings.contentEncodings }) ||
41-
isContentTypeBinary({ headers, binaryContentTypes: binarySettings.contentTypes })
41+
const binaryEncodingTypes = binarySettings.contentEncodings || DEFAULT_BINARY_ENCODINGS
42+
const binaryContentTypes = binarySettings.contentTypes || DEFAULT_BINARY_CONTENT_TYPES
43+
44+
return isContentEncodingBinary({ headers, binaryEncodingTypes }) ||
45+
isContentTypeBinary({ headers, binaryContentTypes })
4246
}

0 commit comments

Comments
 (0)