Skip to content

Commit

Permalink
update packages, fix new Standard JS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffdutton committed Aug 13, 2019
1 parent b5fce7b commit 632d57d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"chai": "^4.2.0",
"coveralls": "^3.0.3",
"coveralls": "^3.0.6",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"standard": "^13.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/events/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const _get = require('lodash.get')
const _has = require('lodash.has')
const typeis = require('type-is').is
const urlParse = require('url').parse
const urlParse = require('url').parse // eslint-disable-line node/no-deprecated-api
const _toString = require('lodash.tostring')
const cookie = require('cookie')
const accepts = require('accepts')
Expand Down
14 changes: 6 additions & 8 deletions src/events/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class Response {
this.headers = {}

if (typeof opts.headers === 'object') {
for (const key in opts.headers) {
Object.keys(opts.headers).forEach(key => {
this.set(key, opts.headers[key])
}
})
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ class Response {
// AWS Lambda doesn't allow arrays for headers, so this is the hack way of
// returning multiple cookies per this thread:
// https://forums.aws.amazon.com/thread.jspa?threadID=205782
if (res.headers.hasOwnProperty(SET_COOKIE) && Array.isArray(res.headers[SET_COOKIE])) {
if ({}.hasOwnProperty.call(res.headers, SET_COOKIE) && Array.isArray(res.headers[SET_COOKIE])) {
const allCookes = res.headers['Set-Cookie']
res.headers[SET_COOKIE] = allCookes.shift()
for (let i = 0; i < allCookes.length; i++) {
Expand Down Expand Up @@ -236,15 +236,13 @@ class Response {
*/
set (field, val) {
if (arguments.length === 2) {
const value = Array.isArray(val)
this.headers[field.toLowerCase()] = Array.isArray(val)
? val.map(_toString)
: _toString(val)

this.headers[field.toLowerCase()] = value
} else {
for (const key in field) {
Object.keys(field).forEach(key => {
this.set(key, field[key])
}
})
}
return this
}
Expand Down
20 changes: 11 additions & 9 deletions test/events/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const expect = require('chai').expect
const Request = require('../../src/events/request')
const GET = require('./test_events').GET
const urlParse = require('url').parse
const urlParse = require('url').parse // eslint-disable-line node/no-deprecated-api

describe('events', () => {
describe('Request', () => {
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('events', () => {
it('should parse headers', () => {
const req = new Request(lambdaEvent)
expect(req.headers).to.eql({
'accept': '*/*',
accept: '*/*',
'accept-encoding': 'gzip, deflate, sdch, br',
'accept-language': 'en-US,en;q=0.8',
'cache-control': 'no-cache',
Expand All @@ -43,13 +43,13 @@ describe('events', () => {
'cloudfront-is-smarttv-viewer': 'false',
'cloudfront-is-tablet-viewer': 'false',
'cloudfront-viewer-country': 'US',
'cookie': 'some=thing; testbool=false; testnull=null',
'host': 'services.cheekyroad.com',
'pragma': 'no-cache',
'referer': 'https://cheekyroad.com/paht/?cool=true',
'referrer': 'https://cheekyroad.com/paht/?cool=true',
cookie: 'some=thing; testbool=false; testnull=null',
host: 'services.cheekyroad.com',
pragma: 'no-cache',
referer: 'https://cheekyroad.com/paht/?cool=true',
referrer: 'https://cheekyroad.com/paht/?cool=true',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36', // eslint-disable-line max-len
'via': '1.1 1a1a1a1.cloudfront.net (CloudFront)',
via: '1.1 1a1a1a1.cloudfront.net (CloudFront)',
'x-amz-cf-id': '2b2b2b2b2==',
'x-forwarded-for': '111.111.111.111, 222.222.222.222',
'x-forwarded-port': '443',
Expand Down Expand Up @@ -100,7 +100,9 @@ describe('events', () => {
lambdaEvent.headers.Referer = 'https://cheekyroad.com/paht/?cool=true#somehash'
const req = new Request(lambdaEvent)
expect(req.referrer).to.eql(urlParse('https://cheekyroad.com/paht/?cool=true#somehash', true))
expect(req.referrer.query.hasOwnProperty('cool')).to.be.true
expect({}.hasOwnProperty.call(req.referrer.query, 'cool')).to.be.true
// It should allow accessing the native way
expect(req.referrer.query.hasOwnProperty('cool')).to.be.true // eslint-disable-line no-prototype-builtins
expect(req.referrer.toString()).to.eq('https://cheekyroad.com/paht/?cool=true#somehash')
})

Expand Down

0 comments on commit 632d57d

Please sign in to comment.