Last active
September 30, 2015 08:57
-
-
Save mtharrison/8d0e53af30f3653a6f8d to your computer and use it in GitHub Desktop.
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
var Hapi = require('hapi'); | |
var Request = require('request'); | |
var server = new Hapi.Server(); | |
server.connection({ port: 4000}); | |
server.route({ | |
method: 'GET', | |
path: '/cookies', | |
handler: function (request, reply) { | |
reply('ok') | |
.header('Set-Cookie', 'cookie1=value1; path=/; HttpOnly', { append: true }) | |
.header('Set-Cookie', 'cookie2=value2; path=/', { append: true }) | |
.header('Set-Cookie', 'cookie3=value3; domain=.domain.com; expires=Wed, 30-Sep-2015 20:31:16 GMT; path=/', { append: true }) | |
.header('Set-Cookie', 'cookie4=value4; expires=Wed, 30-Sep-2015 20:31:16 GMT; path=/', { append: true }) | |
.header('Set-Cookie', 'cookie5=value5; expires=Mon, 28-Sep-2015 20:31:16 GMT; path=/', { append: true }) | |
.header('Set-Cookie', 'cookie6=; domain=.domain.com; expires=Mon, 28-Sep-2015 20:31:16 GMT; path=/', { append: true }) | |
.header('Set-Cookie', 'cookie7=; path=/', { append: true }) | |
} | |
}); | |
server.start(function () { | |
var options = { method: 'GET', | |
url: 'http://localhost:4000/cookies', | |
}; | |
Request(options, function (error, response, body) { | |
if (error || response.statusCode !== 200){ | |
reply(Boom.badRequest('Error')); | |
} | |
console.log(response.headers['set-cookie']); | |
// PRINTS: | |
// [ 'cookie1=value1; path=/; HttpOnly', | |
// 'cookie2=value2; path=/', | |
// 'cookie3=value3; domain=.domain.com; expires=Wed, 30-Sep-2015 20:31:16 GMT; path=/', | |
// 'cookie4=value4; expires=Wed, 30-Sep-2015 20:31:16 GMT; path=/', | |
// 'cookie5=value5; expires=Mon, 28-Sep-2015 20:31:16 GMT; path=/', | |
// 'cookie6=; domain=.domain.com; expires=Mon, 28-Sep-2015 20:31:16 GMT; path=/', | |
// 'cookie7=; path=/' ] | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment