-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* test: full code coverage (#77) * test: moved vary to its own module (#77) * test: added vary module
- Loading branch information
Showing
5 changed files
with
130 additions
and
15 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
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,20 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const vary = require('../vary') | ||
|
||
test('Should not set reply header if none is passed', t => { | ||
t.plan(1) | ||
|
||
const replyMock = { | ||
getHeader (name) { | ||
return [] | ||
}, | ||
header (name, value) { | ||
t.fail('Should not be here') | ||
} | ||
} | ||
|
||
vary(replyMock, []) | ||
t.pass() | ||
}) |
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,16 @@ | ||
'use strict' | ||
|
||
const append = require('vary').append | ||
|
||
// https://github.com/fastify/fastify-sensible/blob/master/lib/vary.js | ||
module.exports = function vary (reply, field) { | ||
var value = reply.getHeader('Vary') || '' | ||
var header = Array.isArray(value) | ||
? value.join(', ') | ||
: String(value) | ||
|
||
// set new header | ||
if ((value = append(header, field))) { | ||
reply.header('Vary', value) | ||
} | ||
} |