Comparing version 0.11.0 to 0.11.1
@@ -165,2 +165,3 @@ // Load modules | ||
}, | ||
compileOptions: {}, | ||
layout: false, | ||
@@ -167,0 +168,0 @@ layoutKeyword: 'content', |
@@ -27,3 +27,3 @@ // Load modules | ||
this.settings.xforward = options.xforward || false; | ||
this.settings.passHeaders = options.passThrough || false; | ||
this.settings.passThrough = options.passThrough || false; | ||
this.settings.isCustomPostResponse = !!options.postResponse; | ||
@@ -60,3 +60,3 @@ this.settings.postResponse = options.postResponse || internals.postResponse; // function (request, settings, response, payload) | ||
if (self.settings.passHeaders) { // Never set with cache | ||
if (self.settings.passThrough) { // Never set with cache | ||
options.headers = Utils.clone(req.headers); | ||
@@ -63,0 +63,0 @@ delete options.headers.host; |
@@ -97,3 +97,2 @@ // Load modules | ||
if (this._request.method !== 'head') { | ||
this._request.raw.res.write(chunk, encoding); | ||
@@ -100,0 +99,0 @@ } |
@@ -7,2 +7,3 @@ // Load modules | ||
var Generic = require('./generic'); | ||
var Headers = require('./headers'); | ||
var Utils = require('../utils'); | ||
@@ -42,7 +43,16 @@ | ||
// Set headers | ||
if (this._flags.location) { | ||
this._headers.Location = Headers.location(this._flags.location, request); | ||
} | ||
Headers.cache(this, request); | ||
Headers.cors(this, request); | ||
// Check if stream is a node HTTP response (stream.*) or a (mikeal's) Request object (stream.response.*) | ||
if (!request._route || | ||
!request._route.config.proxy || | ||
request._route.config.proxy.passThrough) { // Pass headers only if not proxy or proxy with pass-through set | ||
!request._route.proxy || | ||
request._route.proxy.settings.passThrough) { // Pass headers only if not proxy or proxy with pass-through set | ||
@@ -49,0 +59,0 @@ var responseHeaders = this.stream.response ? this.stream.response.headers : this.stream.headers; |
@@ -146,3 +146,3 @@ // Load modules | ||
var source = Fs.readFileSync(fullPath).toString(this.settings.encoding); | ||
var compiled = this.engine.compile(source); | ||
var compiled = this.engine.compile(source, options.compileOptions); | ||
@@ -149,0 +149,0 @@ if (options.cache) { |
@@ -5,3 +5,3 @@ { | ||
"homepage": "http://hapijs.com", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -8,0 +8,0 @@ "contributors": [ |
@@ -39,3 +39,3 @@ // Load modules | ||
var server = new Hapi.Server({ cache: { engine: 'memory' } }); | ||
var server = new Hapi.Server({ cache: { engine: 'memory' }, cors: { origin: ['test.example.com'] } }); | ||
server.addRoute({ method: 'GET', path: '/', config: { handler: handler, cache: { mode: 'client', expiresIn: 9999 } } }); | ||
@@ -49,2 +49,3 @@ server.addState('sid', { encoding: 'base64' }); | ||
expect(res.headers['Cache-Control']).to.equal('max-age=1, must-revalidate'); | ||
expect(res.headers['Access-Control-Allow-Origin']).to.equal('test.example.com'); | ||
expect(res.headers['Set-Cookie']).to.deep.equal(['sid=YWJjZGVmZzEyMzQ1Ng==', 'other=something; Secure', 'x=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT']); | ||
@@ -143,2 +144,31 @@ done(); | ||
var response = new Hapi.Response.Direct(request) | ||
.type('text/plain') | ||
.bytes(13) | ||
.ttl(1000) | ||
.state('sid', 'abcdefg123456') | ||
.write('!hola ') | ||
.write('amigos!'); | ||
request.reply(response); | ||
}; | ||
var server = new Hapi.Server({ cors: { origin: ['test.example.com'] } }); | ||
server.addRoute({ method: 'GET', path: '/', config: { handler: handler, cache: { mode: 'client', expiresIn: 9999 } } }); | ||
server.inject({ method: 'GET', url: '/' }, function (res) { | ||
expect(res.statusCode).to.equal(200); | ||
expect(res.headers['set-cookie']).to.deep.equal(['sid=abcdefg123456']); | ||
expect(res.readPayload()).to.equal('!hola amigos!'); | ||
expect(res.headers['cache-control']).to.equal('max-age=1, must-revalidate'); | ||
expect(res.headers['access-control-allow-origin']).to.equal('test.example.com'); | ||
done(); | ||
}); | ||
}); | ||
it('returns a direct reply (created)', function (done) { | ||
var handler = function (request) { | ||
var response = new Hapi.Response.Direct(request) | ||
.created('me') | ||
@@ -155,3 +185,3 @@ .type('text/plain') | ||
var server = new Hapi.Server({ cache: { engine: 'memory' } }); | ||
var server = new Hapi.Server({ cors: { origin: ['test.example.com'] } }); | ||
server.addRoute({ method: 'GET', path: '/', config: { handler: handler, cache: { mode: 'client', expiresIn: 9999 } } }); | ||
@@ -165,2 +195,4 @@ | ||
expect(res.readPayload()).to.equal('!hola amigos!'); | ||
expect(res.headers['cache-control']).to.equal('no-cache'); | ||
expect(res.headers['access-control-allow-origin']).to.equal('test.example.com'); | ||
done(); | ||
@@ -739,3 +771,6 @@ }); | ||
_streamRequest = request; | ||
request.reply.stream(new FakeStream(request.params.issue)).bytes(request.params.issue ? 0 : 1).send(); | ||
request.reply.stream(new FakeStream(request.params.issue)) | ||
.bytes(request.params.issue ? 0 : 1) | ||
.ttl(2000) | ||
.send(); | ||
}; | ||
@@ -754,5 +789,16 @@ | ||
var server = new Hapi.Server('0.0.0.0', 19798); | ||
server.addRoute({ method: 'GET', path: '/stream/{issue?}', handler: handler }); | ||
var handler3 = function (request) { | ||
_streamRequest = request; | ||
request.reply.stream(new FakeStream(request.params.issue)) | ||
.created('/special') | ||
.bytes(request.params.issue ? 0 : 1) | ||
.ttl(3000) | ||
.send(); | ||
}; | ||
var server = new Hapi.Server('0.0.0.0', 19798, { cors: { origin: ['test.example.com'] } }); | ||
server.addRoute({ method: 'GET', path: '/stream/{issue?}', config: { handler: handler, cache: { mode: 'client', expiresIn: 9999 } } }); | ||
server.addRoute({ method: 'POST', path: '/stream/{issue?}', config: { handler: handler } }); | ||
server.addRoute({ method: 'GET', path: '/stream3', config: { handler: handler3, cache: { mode: 'client', expiresIn: 9999 } } }); | ||
@@ -764,2 +810,5 @@ it('returns a stream reply', function (done) { | ||
expect(res.readPayload()).to.equal('x'); | ||
expect(res.statusCode).to.equal(200); | ||
expect(res.headers['Cache-Control']).to.equal('max-age=2, must-revalidate'); | ||
expect(res.headers['Access-Control-Allow-Origin']).to.equal('test.example.com'); | ||
done(); | ||
@@ -769,2 +818,15 @@ }); | ||
it('returns a stream reply (created)', function (done) { | ||
server.inject({ method: 'GET', url: '/stream3' }, function (res) { | ||
expect(res.readPayload()).to.equal('x'); | ||
expect(res.statusCode).to.equal(201); | ||
expect(res.headers.Location).to.equal(server.settings.uri + '/special'); | ||
expect(res.headers['Cache-Control']).to.equal('no-cache'); | ||
expect(res.headers['Access-Control-Allow-Origin']).to.equal('test.example.com'); | ||
done(); | ||
}); | ||
}); | ||
it('returns a broken stream reply on error issue', function (done) { | ||
@@ -848,3 +910,3 @@ | ||
var msg = "Hello, World!"; | ||
var handler = function (request) { | ||
@@ -878,4 +940,4 @@ | ||
}; | ||
describe('Default', function (done) { | ||
@@ -893,3 +955,3 @@ | ||
server.addRoute({ method: 'GET', path: '/views/invalid', config: { handler: invalidHandler } }); | ||
it('returns a compiled Handlebars template reply', function (done) { | ||
@@ -905,3 +967,3 @@ | ||
}); | ||
it('returns an error absolute path given and allowAbsolutePath is false (by default)', function (done) { | ||
@@ -916,3 +978,3 @@ | ||
}); | ||
it('returns an error if path given includes ../ and allowInsecureAccess is false (by default)', function (done) { | ||
@@ -927,3 +989,3 @@ | ||
}); | ||
it('returns an error if template does not exist', function (done) { | ||
@@ -938,3 +1000,3 @@ | ||
}); | ||
it('returns an error if engine.compile throws', function (done) { | ||
@@ -950,3 +1012,3 @@ | ||
}) | ||
describe('Layout', function (done) { | ||
@@ -962,3 +1024,3 @@ | ||
layoutServer.addRoute({ method: 'GET', path: '/layout/abspath', config: { handler: layoutErrHandler } }); | ||
it('returns error on layoutKeyword conflict', function (done) { | ||
@@ -973,3 +1035,3 @@ | ||
}); | ||
it('returns an error absolute path given and allowAbsolutePath is false (by default)', function (done) { | ||
@@ -976,0 +1038,0 @@ |
Sorry, the diff of this file is too big to display
562762
127
9059