@hapi/hapi
Advanced tools
Comparing version 19.1.1 to 19.2.0
@@ -122,3 +122,4 @@ 'use strict'; | ||
onPostHandler: Joi.array().items(internals.event).single(), | ||
onPreResponse: Joi.array().items(internals.event).single() | ||
onPreResponse: Joi.array().items(internals.event).single(), | ||
onPostResponse: Joi.array().items(internals.event).single() | ||
}) | ||
@@ -125,0 +126,0 @@ .default({}), |
@@ -27,2 +27,3 @@ 'use strict'; | ||
const Request = require('./request'); | ||
const Response = require('./response'); | ||
const Route = require('./route'); | ||
@@ -72,2 +73,3 @@ const Toolkit = require('./toolkit'); | ||
Request = class extends Request { }; | ||
Response = class extends Response { }; | ||
requestCounter = { value: internals.counter.min, min: internals.counter.min, max: internals.counter.max }; | ||
@@ -99,3 +101,4 @@ root = null; | ||
onPostHandler: new Ext('onPostHandler', this), | ||
onPreResponse: new Ext('onPreResponse', this) | ||
onPreResponse: new Ext('onPreResponse', this), | ||
onPostResponse: new Ext('onPostResponse', this) | ||
} | ||
@@ -107,6 +110,7 @@ }; | ||
request: new Map(), | ||
response: new Map(), | ||
server: new Map(), | ||
toolkit: new Map(), | ||
requestApply: null, | ||
public: { handler: [], request: [], server: [], toolkit: [] } | ||
public: { handler: [], request: [], response: [], server: [], toolkit: [] } | ||
}; | ||
@@ -113,0 +117,0 @@ |
@@ -8,5 +8,3 @@ 'use strict'; | ||
const Response = require('./response'); | ||
const internals = {}; | ||
@@ -28,4 +26,4 @@ | ||
const ttl = (response.settings.ttl !== null ? response.settings.ttl : request._route._cache.ttl()); | ||
const privacy = (request.auth.isAuthenticated || response.headers['set-cookie'] ? 'private' : settings.privacy || 'default'); | ||
const ttl = response.settings.ttl !== null ? response.settings.ttl : request._route._cache.ttl(); | ||
const privacy = request.auth.isAuthenticated || response.headers['set-cookie'] ? 'private' : settings.privacy || 'default'; | ||
response._header('cache-control', 'max-age=' + Math.floor(ttl / 1000) + ', must-revalidate' + (privacy !== 'default' ? ', ' + privacy : '')); | ||
@@ -62,7 +60,7 @@ } | ||
if (!response._isPayloadSupported()) { | ||
response._close(request); // Close unused file streams | ||
response._close(); // Close unused file streams | ||
response._payload = new internals.Empty(); // Set empty stream | ||
} | ||
exports.type(request, true); | ||
exports.type(request); | ||
} | ||
@@ -73,3 +71,3 @@ else { | ||
response._close(request); // Close unused file streams | ||
response._close(); // Close unused file streams | ||
response._payload = new internals.Empty(); | ||
@@ -127,24 +125,9 @@ delete response.headers['content-length']; | ||
exports.type = function (request, postMarshal) { | ||
exports.type = function (request) { | ||
const response = request.response; | ||
let type = response.headers['content-type']; | ||
if (!type) { | ||
if (response._contentType) { | ||
const charset = (response.settings.charset && response._contentType !== 'application/octet-stream' ? '; charset=' + response.settings.charset : ''); | ||
response.type(response._contentType + charset); | ||
} | ||
const type = response.contentType; | ||
if (type !== response.headers['content-type']) { | ||
response.type(type); | ||
} | ||
else { | ||
type = type.trim(); | ||
if ((!response._contentType || !postMarshal) && | ||
response.settings.charset && | ||
type.match(/^(?:text\/)|(?:application\/(?:json)|(?:javascript))/)) { | ||
if (!type.match(/; *charset=/)) { | ||
const semi = (type[type.length - 1] === ';'); | ||
response.type(type + (semi ? ' ' : '; ') + 'charset=' + (response.settings.charset)); | ||
} | ||
} | ||
} | ||
}; | ||
@@ -188,3 +171,3 @@ | ||
const etag = Response.unmodified(request, entity); | ||
const etag = request._core.Response.unmodified(request, entity); | ||
if (etag) { | ||
@@ -191,0 +174,0 @@ response.code(304); |
@@ -12,3 +12,2 @@ 'use strict'; | ||
const Cors = require('./cors'); | ||
const Response = require('./response'); | ||
const Toolkit = require('./toolkit'); | ||
@@ -370,3 +369,3 @@ const Transmit = require('./transmit'); | ||
Bounce.rethrow(err, 'system'); | ||
response = Response.wrap(err, this); | ||
response = this._core.Response.wrap(err, this); | ||
} | ||
@@ -389,3 +388,3 @@ | ||
async _invoke(event) { | ||
async _invoke(event, options = {}) { | ||
@@ -395,4 +394,12 @@ for (const ext of event.nodes) { | ||
const bind = ext.bind || realm.settings.bind; | ||
const response = await this._core.toolkit.execute(ext.func, this, { bind, realm, timeout: ext.timeout, name: event.type }); | ||
const response = await this._core.toolkit.execute(ext.func, this, { bind, realm, timeout: ext.timeout, name: event.type, ignoreResponse: options.ignoreResponse }); | ||
if (options.ignoreResponse) { | ||
if (Boom.isBoom(response)) { | ||
this._log(['ext', 'error'], response); | ||
} | ||
continue; | ||
} | ||
if (response === Toolkit.symbols.continue) { | ||
@@ -430,3 +437,3 @@ continue; | ||
if (exit) { // Can be a valid response or error (if returned from an ext, already handled because this.response is also set) | ||
this._setResponse(Response.wrap(exit, this)); // Wrap to ensure any object thrown is always a valid Boom or Response object | ||
this._setResponse(this._core.Response.wrap(exit, this)); // Wrap to ensure any object thrown is always a valid Boom or Response object | ||
} | ||
@@ -464,3 +471,3 @@ | ||
Bounce.rethrow(err, 'system'); | ||
response = Response.wrap(err, this); | ||
response = this._core.Response.wrap(err, this); | ||
} | ||
@@ -487,22 +494,24 @@ | ||
if (this.response && | ||
this.response.statusCode === 500 && | ||
this.response._error) { | ||
this._eventContext.request = null; // Disable req events | ||
const tags = this.response._error.isDeveloperError ? ['internal', 'implementation', 'error'] : ['internal', 'error']; | ||
this._log(tags, this.response._error, 'error'); | ||
} | ||
if (!Boom.isBoom(this.response)) { | ||
if (this.response.statusCode === 500 && | ||
this.response._error) { | ||
// Cleanup | ||
const tags = this.response._error.isDeveloperError ? ['internal', 'implementation', 'error'] : ['internal', 'error']; | ||
this._log(tags, this.response._error, 'error'); | ||
} | ||
this._eventContext.request = null; // Disable req events | ||
if (this.response && | ||
this.response._close) { | ||
this.response._close(this); | ||
if (this.response._close) { | ||
this.response._close(); | ||
} | ||
} | ||
this.info.completed = Date.now(); | ||
this._core.events.emit('response', this); | ||
if (this._route._extensions.onPostResponse.nodes) { | ||
this._invoke(this._route._extensions.onPostResponse, { ignoreResponse: true }); | ||
} | ||
} | ||
@@ -517,3 +526,3 @@ | ||
this.response._close(this); | ||
this.response._close(); | ||
} | ||
@@ -523,3 +532,3 @@ | ||
if (response._close) { | ||
response._close(this); | ||
response._close(); | ||
} | ||
@@ -563,3 +572,3 @@ | ||
return new Response.Peek(this._events); | ||
return new this._core.Response.Peek(this._events); | ||
} | ||
@@ -608,3 +617,3 @@ | ||
return new Response(source, this, options); | ||
return new this._core.Response(source, this, options); | ||
} | ||
@@ -712,6 +721,8 @@ }; | ||
if (event === 'abort' && | ||
request._events) { | ||
if (event === 'abort') { | ||
request._setResponse(new Boom.Boom('Request aborted', { statusCode: request.route.settings.response.disconnectStatusCode })); | ||
request._events.emit('disconnect'); | ||
if (request._events) { | ||
request._events.emit('disconnect'); | ||
} | ||
} | ||
@@ -718,0 +729,0 @@ }; |
@@ -24,3 +24,8 @@ 'use strict'; | ||
'upgrade': true | ||
} | ||
}, | ||
reserved: ['app', 'headers', 'plugins', 'request', 'source', 'statusCode', 'variety', | ||
'settings', 'events', 'code', 'message', 'header', 'vary', 'etag', 'type', 'contentType', | ||
'bytes', 'location', 'created', 'compressed', 'replacer', 'space', 'suffix', 'escape', | ||
'passThrough', 'redirect', 'temporary', 'permanent', 'rewritable', 'encoding', 'charset', | ||
'ttl', 'state', 'unstate', 'takeover'] | ||
}; | ||
@@ -65,6 +70,2 @@ | ||
this.temporary = null; | ||
this.permanent = null; | ||
this.rewritable = null; | ||
this._setSource(source, options.variety); | ||
@@ -75,3 +76,3 @@ } | ||
if (result instanceof internals.Response || | ||
if (result instanceof request._core.Response || | ||
typeof result === 'symbol') { | ||
@@ -86,3 +87,3 @@ | ||
return new internals.Response(result, request); | ||
return new request._core.Response(result, request); | ||
} | ||
@@ -205,3 +206,3 @@ | ||
const entity = internals.Response.entity(tag, options); | ||
const entity = this.request._core.Response.entity(tag, options); | ||
this._header('etag', entity.etag); | ||
@@ -295,2 +296,26 @@ this.settings.varyEtag = entity.vary; | ||
get contentType() { | ||
let type = this.headers['content-type']; | ||
if (type) { | ||
type = type.trim(); | ||
if (this.settings.charset && | ||
type.match(/^(?:text\/)|(?:application\/(?:json)|(?:javascript))/) && | ||
!type.match(/; *charset=/)) { | ||
const semi = type[type.length - 1] === ';'; | ||
return type + (semi ? ' ' : '; ') + 'charset=' + this.settings.charset; | ||
} | ||
return type; | ||
} | ||
if (this._contentType) { | ||
const charset = this.settings.charset && this._contentType !== 'application/octet-stream' ? '; charset=' + this.settings.charset : ''; | ||
return this._contentType + charset; | ||
} | ||
return null; | ||
} | ||
bytes(bytes) { | ||
@@ -364,10 +389,9 @@ | ||
this.location(location); | ||
this.temporary = this._temporary; | ||
this.permanent = this._permanent; | ||
this.rewritable = this._rewritable; | ||
return this; | ||
} | ||
_temporary(isTemporary) { | ||
temporary(isTemporary) { | ||
Hoek.assert(this.headers.location, 'Cannot set redirection mode without first setting a location'); | ||
this._setTemporary(isTemporary !== false); // Defaults to true | ||
@@ -377,4 +401,6 @@ return this; | ||
_permanent(isPermanent) { | ||
permanent(isPermanent) { | ||
Hoek.assert(this.headers.location, 'Cannot set redirection mode without first setting a location'); | ||
this._setTemporary(isPermanent === false); // Defaults to true | ||
@@ -384,4 +410,6 @@ return this; | ||
_rewritable(isRewritable) { | ||
rewritable(isRewritable) { | ||
Hoek.assert(this.headers.location, 'Cannot set redirection mode without first setting a location'); | ||
this._setRewritable(isRewritable !== false); // Defaults to true | ||
@@ -558,10 +586,2 @@ return this; | ||
if (Streams.isStream(source)) { | ||
if (typeof source._read !== 'function') { | ||
throw Boom.badImplementation('Stream must have a readable interface'); | ||
} | ||
if (source._readableState.objectMode) { | ||
throw Boom.badImplementation('Cannot reply with stream in object mode'); | ||
} | ||
this._payload = source; | ||
@@ -629,3 +649,3 @@ return; | ||
_close(request) { | ||
_close() { | ||
@@ -638,3 +658,3 @@ if (this._processors.close) { | ||
Bounce.rethrow(err, 'system'); | ||
request._log(['response', 'cleanup', 'error'], err); | ||
this.request._log(['response', 'cleanup', 'error'], err); | ||
} | ||
@@ -656,5 +676,3 @@ } | ||
if (stream.unpipe) { | ||
stream.unpipe(); | ||
} | ||
stream.unpipe(); | ||
@@ -664,8 +682,5 @@ if (stream.close) { | ||
} | ||
else if (stream.destroy) { | ||
else { | ||
stream.destroy(); | ||
} | ||
else { | ||
Streams.drain(stream); | ||
} | ||
} | ||
@@ -675,2 +690,5 @@ }; | ||
internals.Response.reserved = internals.reserved; | ||
internals.parseDate = function (string) { | ||
@@ -677,0 +695,0 @@ |
@@ -167,3 +167,4 @@ 'use strict'; | ||
this._extensions = { | ||
onPreResponse: Ext.combine(this, 'onPreResponse') | ||
onPreResponse: Ext.combine(this, 'onPreResponse'), | ||
onPostResponse: Ext.combine(this, 'onPostResponse') | ||
}; | ||
@@ -327,2 +328,4 @@ | ||
this._buildMarshalCycle(); | ||
// onPostResponse | ||
} | ||
@@ -329,0 +332,0 @@ |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const Somever = require('@hapi/somever'); | ||
const Teamwork = require('@hapi/teamwork'); | ||
@@ -14,3 +15,2 @@ const Config = require('./config'); | ||
const Package = require('../package.json'); | ||
const Request = require('./request'); | ||
const Route = require('./route'); | ||
@@ -64,3 +64,4 @@ const Toolkit = require('./toolkit'); | ||
onPostHandler: new Ext('onPostHandler', core), | ||
onPreResponse: new Ext('onPreResponse', core) | ||
onPreResponse: new Ext('onPreResponse', core), | ||
onPostResponse: new Ext('onPostResponse', core) | ||
}, | ||
@@ -150,3 +151,3 @@ modifiers: { | ||
Hoek.assert(!Request.reserved.includes(property), 'Cannot override built-in request interface decoration:', propertyName); | ||
Hoek.assert(!this._core.Request.reserved.includes(property), 'Cannot override built-in request interface decoration:', propertyName); | ||
@@ -161,2 +162,9 @@ if (options.apply) { | ||
} | ||
else if (type === 'response') { | ||
// Response | ||
Hoek.assert(!this._core.Response.reserved.includes(property), 'Cannot override built-in response interface decoration:', propertyName); | ||
this._core.Response.prototype[property] = method; | ||
} | ||
else if (type === 'toolkit') { | ||
@@ -234,3 +242,3 @@ | ||
plugin = plugin.replace(/^\@([^\/]+)\//, ($0, $1) => { | ||
plugin = plugin.replace(/^@([^/]+)\//, ($0, $1) => { | ||
@@ -253,3 +261,15 @@ return !options.scope ? '' : `${$1}__`; | ||
let promise; | ||
if (typeof events === 'string') { | ||
if (!method) { | ||
const team = new Teamwork.Team(); | ||
method = (request, h) => { | ||
team.attend(request); | ||
return h.continue; | ||
}; | ||
promise = team.work; | ||
} | ||
events = { type: events, method, options }; | ||
@@ -262,2 +282,4 @@ } | ||
} | ||
return promise; | ||
} | ||
@@ -477,5 +499,2 @@ | ||
} | ||
catch (err) { | ||
throw err; | ||
} | ||
finally { | ||
@@ -482,0 +501,0 @@ --this._core.registring; |
'use strict'; | ||
const Boom = require('@hapi/boom'); | ||
const Teamwork = require('@hapi/teamwork'); | ||
@@ -13,5 +14,18 @@ | ||
return stream && | ||
typeof stream === 'object' && | ||
typeof stream.pipe === 'function'; | ||
if (!stream || | ||
typeof stream !== 'object' || | ||
typeof stream.pipe !== 'function') { | ||
return false; | ||
} | ||
if (typeof stream._read !== 'function') { | ||
throw Boom.badImplementation('Stream must have a readable interface'); | ||
} | ||
if (stream._readableState.objectMode) { | ||
throw Boom.badImplementation('Cannot reply with stream in object mode'); | ||
} | ||
return true; | ||
}; | ||
@@ -18,0 +32,0 @@ |
@@ -7,5 +7,3 @@ 'use strict'; | ||
const Response = require('./response'); | ||
const internals = {}; | ||
@@ -56,9 +54,7 @@ | ||
} | ||
else if (options.args) { | ||
operation = method(request, h, ...options.args); | ||
} | ||
else { | ||
if (options.args) { | ||
operation = method(request, h, ...options.args); | ||
} | ||
else { | ||
operation = method(request, h); | ||
} | ||
operation = method(request, h); | ||
} | ||
@@ -82,2 +78,6 @@ | ||
if (options.ignoreResponse) { | ||
return response; | ||
} | ||
if (response === undefined) { | ||
@@ -106,3 +106,3 @@ response = Boom.badImplementation(`${method.name} method did not return a value, a promise, or throw an error`); | ||
if (typeof response !== 'symbol') { | ||
response = Response.wrap(response, request); | ||
response = request._core.Response.wrap(response, request); | ||
if (!response.isBoom) { | ||
@@ -198,3 +198,3 @@ response = await response._prepare(); | ||
return Response.wrap(result, this.request); | ||
return this.request._core.Response.wrap(result, this.request); | ||
} | ||
@@ -214,4 +214,4 @@ | ||
const entity = Response.entity(options.etag, options); | ||
if (Response.unmodified(this.request, entity)) { | ||
const entity = this.request._core.Response.entity(options.etag, options); | ||
if (this.request._core.Response.unmodified(this.request, entity)) { | ||
return this.response().code(304).takeover(); | ||
@@ -218,0 +218,0 @@ } |
@@ -13,3 +13,2 @@ 'use strict'; | ||
const Config = require('./config'); | ||
const Response = require('./response'); | ||
@@ -68,3 +67,3 @@ | ||
response._payload = new Response.Payload(JSON.stringify(minimal), {}); | ||
response._payload = new request._core.Response.Payload(JSON.stringify(minimal), {}); | ||
} | ||
@@ -79,3 +78,3 @@ | ||
const error = boom.output; | ||
const response = new Response(error.payload, request); | ||
const response = new request._core.Response(error.payload, request); | ||
response._error = boom; | ||
@@ -296,3 +295,3 @@ response.code(error.statusCode); | ||
request.raw.res.destroy(); | ||
Response.drain(stream); | ||
request._core.Response.drain(stream); | ||
} | ||
@@ -299,0 +298,0 @@ |
@@ -1,2 +0,2 @@ | ||
Copyright (c) 2011-2019, Sideway Inc, and project contributors | ||
Copyright (c) 2011-2020, Sideway Inc, and project contributors | ||
Copyright (c) 2011-2014, Walmart | ||
@@ -3,0 +3,0 @@ Copyright (c) 2011, Yahoo Inc. |
{ | ||
"name": "@hapi/hapi", | ||
"description": "HTTP Server framework", | ||
"homepage": "https://hapijs.com", | ||
"version": "19.1.1", | ||
"homepage": "https://hapi.dev", | ||
"version": "19.2.0", | ||
"repository": "git://github.com/hapijs/hapi", | ||
"main": "lib/index.js", | ||
"engines": { | ||
"node": ">=12.0.0" | ||
}, | ||
"files": [ | ||
@@ -23,3 +26,3 @@ "lib" | ||
"@hapi/call": "8.x.x", | ||
"@hapi/catbox": "11.x.x", | ||
"@hapi/catbox": "^11.1.0", | ||
"@hapi/catbox-memory": "5.x.x", | ||
@@ -26,0 +29,0 @@ "@hapi/heavy": "7.x.x", |
@@ -0,1 +1,3 @@ | ||
## The hapi project is changing direction... [Find out more](https://github.com/hapijs/hapi/issues/4111). | ||
<img src="https://raw.githubusercontent.com/hapijs/assets/master/images/hapi.png" width="400px" /> | ||
@@ -2,0 +4,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179743
4564
20
Updated@hapi/catbox@^11.1.0