@nodefony/http-bundle
Advanced tools
Comparing version 4.0.0-beta.8 to 4.0.0-beta.9
module.exports = class httpBundle extends nodefony.Bundle { | ||
constructor(name, kernel, container) { | ||
super(name, kernel, container); | ||
this.autoLoader.loadDirectory(path.resolve(this.path, "src")); | ||
this.autoLoader.loadDirectory(path.resolve(this.path, "src"), /errors/); | ||
this.autoLoader.load(path.resolve(this.path, "src", "errors", "httpError.js")); | ||
this.autoLoader.load(path.resolve(this.path, "src", "errors", "errorRequest.js")); | ||
} | ||
}; |
{ | ||
"name": "@nodefony/http-bundle", | ||
"version": "4.0.0-beta.8", | ||
"version": "4.0.0-beta.9", | ||
"description": "Nodefony Framework Bundle HTTP ", | ||
@@ -22,2 +22,3 @@ "contributors": [], | ||
"qs": "^6.5.2", | ||
"request": "^2.88.0", | ||
"serve-static": "^1.13.2", | ||
@@ -24,0 +25,0 @@ "sockjs": "^0.3.19", |
@@ -38,2 +38,6 @@ module.exports = { | ||
}, | ||
requestClient: { | ||
class: nodefony.services.requestClient, | ||
arguments: ["@container"] | ||
} | ||
}; |
@@ -213,2 +213,3 @@ /* | ||
getTransDefaultDomain: context.translation.getTransDefaultDomain.bind(context.translation), | ||
getUser: context.getUser.bind(context), | ||
CDN: (type, nb) => { | ||
@@ -320,2 +321,6 @@ let cdn = this.getCDN(type, nb); | ||
} | ||
if (!httpError.context) { | ||
httpError.context = container.get("context"); | ||
httpError.resolve(); | ||
} | ||
context = httpError.context; | ||
@@ -322,0 +327,0 @@ context.resolver = httpError.resolver; |
@@ -30,14 +30,14 @@ /* | ||
switch (setting) { | ||
case true: | ||
case "": | ||
case undefined: | ||
return "default"; | ||
case false: | ||
case null: | ||
return null; | ||
default: | ||
if (typeof setting === "string") { | ||
return setting; | ||
} | ||
throw new Error("Session start settings config error : " + setting); | ||
case true: | ||
case "": | ||
case undefined: | ||
return "default"; | ||
case false: | ||
case null: | ||
return null; | ||
default: | ||
if (typeof setting === "string") { | ||
return setting; | ||
} | ||
throw new Error("Session start settings config error : " + setting); | ||
} | ||
@@ -49,12 +49,12 @@ } | ||
switch (this.settings.handler) { | ||
case "orm": | ||
case "ORM": | ||
storage = nodefony.session.storage[this.kernel.getOrm()]; | ||
break; | ||
default: | ||
storage = nodefony.session.storage[this.settings.handler]; | ||
case "orm": | ||
case "ORM": | ||
storage = nodefony.session.storage[this.kernel.getOrm()]; | ||
break; | ||
default: | ||
storage = nodefony.session.storage[this.settings.handler]; | ||
} | ||
if (storage) { | ||
this.storage = new storage(this); | ||
this.listen(this, "onReady", function () { | ||
this.listen(this, "onReady", function() { | ||
this.storage.open("default"); | ||
@@ -123,3 +123,3 @@ }); | ||
if (this.storage) { | ||
this.listen(this, "onReady", function () { | ||
this.listen(this, "onReady", function() { | ||
this.storage.open(context); | ||
@@ -126,0 +126,0 @@ }); |
@@ -142,3 +142,3 @@ nodefony.register("Context", () => { | ||
getUser() { | ||
return this.user || null; | ||
return this.user || null; | ||
} | ||
@@ -164,3 +164,3 @@ | ||
} | ||
if (typeof (role) === "string") { | ||
if (typeof(role) === "string") { | ||
return this.token.hasRole(role); | ||
@@ -211,3 +211,3 @@ } else { | ||
} | ||
if (!this.resolver.route) { | ||
/*if (!this.resolver.route) { | ||
return false; | ||
@@ -217,11 +217,11 @@ } | ||
return false; | ||
} | ||
}*/ | ||
switch (true) { | ||
case this.response.body instanceof Buffer: | ||
this.response.body = this.response.body.toString(this.response.encoding); | ||
break; | ||
case (typeof this.response.body === "string"): | ||
break; | ||
default: | ||
return false; | ||
case this.response.body instanceof Buffer: | ||
this.response.body = this.response.body.toString(this.response.encoding); | ||
break; | ||
case (typeof this.response.body === "string"): | ||
break; | ||
default: | ||
return false; | ||
} | ||
@@ -228,0 +228,0 @@ if (this.response.body.indexOf("</body>") >= 0) { |
@@ -1,2 +0,2 @@ | ||
nodefony.register.call(nodefony.context, "http", function () { | ||
nodefony.register.call(nodefony.context, "http", function() { | ||
@@ -14,3 +14,2 @@ const Http = class httpContext extends nodefony.Context { | ||
this.pushAllowed = false; | ||
if (this.type === "HTTP2") { | ||
@@ -25,6 +24,11 @@ this.request = new nodefony.http2Request(request, this); | ||
this.cookieSession = this.getCookieSession(this.sessionService.settings.name); | ||
/*this.once("onRequestEnd", () => { | ||
this.requestEnded = true; | ||
});*/ | ||
this.once("onRequestEnd", () => { | ||
try { | ||
if (this.isRedirect) { | ||
return this.send(); | ||
} | ||
} catch (e) { | ||
this.fire("onError", this.container, e); | ||
} | ||
}); | ||
this.method = this.request.getMethod(); | ||
@@ -104,11 +108,2 @@ this.isAjax = this.request.isAjax(); | ||
handle(data) { | ||
this.setParameters("query.get", this.request.queryGet); | ||
if (this.request.queryPost) { | ||
this.setParameters("query.post", this.request.queryPost); | ||
} | ||
if (this.request.queryFile) { | ||
this.setParameters("query.files", this.request.queryFile); | ||
} | ||
this.setParameters("query.request", this.request.query); | ||
try { | ||
@@ -118,2 +113,10 @@ if (this.isRedirect) { | ||
} | ||
this.setParameters("query.get", this.request.queryGet); | ||
if (this.request.queryPost) { | ||
this.setParameters("query.post", this.request.queryPost); | ||
} | ||
if (this.request.queryFile) { | ||
this.setParameters("query.files", this.request.queryFile); | ||
} | ||
this.setParameters("query.request", this.request.query); | ||
this.locale = this.translation.handle(); | ||
@@ -211,3 +214,3 @@ if (!this.resolver) { | ||
} | ||
if ( !this.profiler) { | ||
if (!this.profiler) { | ||
if (this.profiling) { | ||
@@ -298,19 +301,19 @@ this.fire("onSendMonitoring", this.response, this); | ||
switch (nodefony.typeOf(xjson)) { | ||
case "object": | ||
this.response.setHeader("X-Json", JSON.stringify(xjson)); | ||
return xjson; | ||
case "string": | ||
this.response.setHeader("X-Json", xjson); | ||
return JSON.parse(xjson); | ||
case "Error": | ||
if (typeof xjson.message === "object") { | ||
this.response.setHeader("X-Json", JSON.stringify(xjson.message)); | ||
return xjson.message; | ||
} else { | ||
this.response.setHeader("X-Json", xjson.message); | ||
return { | ||
error: xjson.message | ||
}; | ||
} | ||
break; | ||
case "object": | ||
this.response.setHeader("X-Json", JSON.stringify(xjson)); | ||
return xjson; | ||
case "string": | ||
this.response.setHeader("X-Json", xjson); | ||
return JSON.parse(xjson); | ||
case "Error": | ||
if (typeof xjson.message === "object") { | ||
this.response.setHeader("X-Json", JSON.stringify(xjson.message)); | ||
return xjson.message; | ||
} else { | ||
this.response.setHeader("X-Json", xjson.message); | ||
return { | ||
error: xjson.message | ||
}; | ||
} | ||
break; | ||
} | ||
@@ -317,0 +320,0 @@ } |
const http = require("http"); | ||
const mime = require('mime'); | ||
module.exports = nodefony.register("Response", function () { | ||
module.exports = nodefony.register("Response", function() { | ||
@@ -68,6 +68,5 @@ const Response = class httpResponse { | ||
setCookie(cookie) { | ||
//this.response.on('header', function(){ | ||
this.logger("ADD COOKIE ==> " + cookie.serialize(), "DEBUG"); | ||
return this.setHeader('Set-Cookie', cookie.serialize()); | ||
//}.bind(this)) | ||
let serialize = cookie.serialize(); | ||
this.logger("ADD COOKIE ==> " + serialize, "DEBUG"); | ||
return this.setHeader('Set-Cookie', serialize); | ||
} | ||
@@ -113,3 +112,3 @@ | ||
this.contentType = myType; | ||
return this.setHeader("Content-Type", myType + " ; charset=" + (encoding || this.encoding)); | ||
return this.setHeader("Content-Type", myType + " ; charset=" + (encoding || this.encoding)); | ||
} | ||
@@ -269,11 +268,11 @@ | ||
switch (nodefony.typeOf(headers)) { | ||
case "object": | ||
this.setHeaders(headers); | ||
break; | ||
case "boolean": | ||
this.setHeaders({ | ||
"Cache-Control": "no-store, no-cache, must-revalidate", | ||
"Expires": "Thu, 01 Jan 1970 00:00:00 GMT" | ||
}); | ||
break; | ||
case "object": | ||
this.setHeaders(headers); | ||
break; | ||
case "boolean": | ||
this.setHeaders({ | ||
"Cache-Control": "no-store, no-cache, must-revalidate", | ||
"Expires": "Thu, 01 Jan 1970 00:00:00 GMT" | ||
}); | ||
break; | ||
} | ||
@@ -280,0 +279,0 @@ } |
const cookieLib = require('cookie'); | ||
const MS = require('ms'); | ||
nodefony.register("cookies", function () { | ||
nodefony.register("cookies", function() { | ||
@@ -19,37 +19,37 @@ const encode = encodeURIComponent; | ||
const parse = function (strToParse) { | ||
const parse = function(strToParse) { | ||
return cookieLib.parse(strToParse); | ||
}; | ||
const cookiesParser = function (context) { | ||
const cookiesParser = function(context) { | ||
let cookies = null; | ||
let co = null; | ||
switch (context.type) { | ||
case "HTTP": | ||
case "HTTPS": | ||
case "HTTP2": | ||
if (context.request.request && context.request.request.headers.cookie) { | ||
cookies = context.request.request.headers.cookie; | ||
} | ||
if (cookies) { | ||
let obj = parse(cookies); | ||
for (let cookie in obj) { | ||
co = new Cookie(cookie, obj[cookie]); | ||
context.addCookie(co); | ||
case "HTTP": | ||
case "HTTPS": | ||
case "HTTP2": | ||
if (context.request.request && context.request.request.headers.cookie) { | ||
cookies = context.request.request.headers.cookie; | ||
} | ||
context.request.request.cookies = context.cookies; | ||
} | ||
break; | ||
case "WEBSOCKET": | ||
case "WEBSOCKET SECURE": | ||
if (context.request.cookies) { | ||
cookies = context.request.cookies; | ||
} | ||
if (cookies) { | ||
for (let i = 0; i < cookies.length; i++) { | ||
co = new Cookie(cookies[i].name, cookies[i].value); | ||
context.addCookie(co); | ||
if (cookies) { | ||
let obj = parse(cookies); | ||
for (let cookie in obj) { | ||
co = new Cookie(cookie, obj[cookie]); | ||
context.addCookie(co); | ||
} | ||
context.request.request.cookies = context.cookies; | ||
} | ||
} | ||
break; | ||
break; | ||
case "WEBSOCKET": | ||
case "WEBSOCKET SECURE": | ||
if (context.request.cookies) { | ||
cookies = context.request.cookies; | ||
} | ||
if (cookies) { | ||
for (let i = 0; i < cookies.length; i++) { | ||
co = new Cookie(cookies[i].name, cookies[i].value); | ||
context.addCookie(co); | ||
} | ||
} | ||
break; | ||
} | ||
@@ -150,13 +150,13 @@ }; | ||
switch (typeof ms) { | ||
case "number": | ||
return ms; | ||
case "string": | ||
try { | ||
res = MS(ms) / 1000; | ||
} catch (e) { | ||
res = ms; | ||
} | ||
return parseInt(res, 10); | ||
default: | ||
throw new Error("cookie class error maxage bad type " + typeof ms); | ||
case "number": | ||
return ms; | ||
case "string": | ||
try { | ||
res = MS(ms) / 1000; | ||
} catch (e) { | ||
res = ms; | ||
} | ||
return parseInt(res, 10); | ||
default: | ||
throw new Error("cookie class error maxage bad type " + typeof ms); | ||
} | ||
@@ -163,0 +163,0 @@ } |
@@ -140,4 +140,4 @@ module.exports = nodefony.register("httpError", function () { | ||
break; | ||
//default: | ||
// this.message = message; | ||
default: | ||
return super.parseMessage(message); | ||
} | ||
@@ -144,0 +144,0 @@ } |
@@ -5,3 +5,3 @@ /* | ||
*/ | ||
nodefony.register("Session", function () { | ||
nodefony.register("Session", function() { | ||
@@ -11,14 +11,14 @@ const algorithm = 'aes-256-ctr'; | ||
const checkSecureReferer = function () { | ||
const checkSecureReferer = function() { | ||
let host = null; | ||
switch (this.context.type) { | ||
case "HTTP": | ||
case "HTTPS": | ||
case "HTTP2": | ||
host = this.context.request.request.headers.host; | ||
break; | ||
case "WEBSOCKET": | ||
case "WEBSOCKET SECURE": | ||
host = this.context.request.httpRequest.headers.host; | ||
break; | ||
case "HTTP": | ||
case "HTTPS": | ||
case "HTTP2": | ||
host = this.context.request.request.headers.host; | ||
break; | ||
case "WEBSOCKET": | ||
case "WEBSOCKET SECURE": | ||
host = this.context.request.httpRequest.headers.host; | ||
break; | ||
} | ||
@@ -37,3 +37,3 @@ let meta = this.getMetaBag("host"); | ||
const setMetasSession = function () { | ||
const setMetasSession = function() { | ||
let time = new Date(); | ||
@@ -120,10 +120,10 @@ this.setMetaBag("lifetime", this.settings.cookie.maxAge); | ||
switch (ret) { | ||
case false: | ||
return new Promise((resolve /*, reject*/ ) => { | ||
return resolve(this); | ||
}); | ||
case "restart": | ||
return this.start(context, contextSession); | ||
default: | ||
return this.getSession(contextSession); | ||
case false: | ||
return new Promise((resolve /*, reject*/ ) => { | ||
return resolve(this); | ||
}); | ||
case "restart": | ||
return this.start(context, contextSession); | ||
default: | ||
return this.getSession(contextSession); | ||
} | ||
@@ -139,19 +139,19 @@ } catch (e) { | ||
switch (this.status) { | ||
case "active": | ||
this.manager.logger("SESSION ALLREADY STARTED ==> " + this.name + " : " + this.id, "WARNING"); | ||
return false; | ||
case "disabled": | ||
try { | ||
this.storage = this.manager.initializeStorage(); | ||
if (this.storage) { | ||
this.status = "none"; | ||
return "restart"; | ||
case "active": | ||
this.manager.logger("SESSION ALLREADY STARTED ==> " + this.name + " : " + this.id, "WARNING"); | ||
return false; | ||
case "disabled": | ||
try { | ||
this.storage = this.manager.initializeStorage(); | ||
if (this.storage) { | ||
this.status = "none"; | ||
return "restart"; | ||
} | ||
} catch (e) { | ||
this.manager.logger("SESSION STORAGE HANDLER NOT FOUND ", "ERROR"); | ||
throw new Error("SESSION STORAGE HANDLER NOT FOUND "); | ||
} | ||
} catch (e) { | ||
this.manager.logger("SESSION STORAGE HANDLER NOT FOUND ", "ERROR"); | ||
throw new Error("SESSION STORAGE HANDLER NOT FOUND "); | ||
} | ||
break; | ||
default: | ||
return true; | ||
break; | ||
default: | ||
return true; | ||
} | ||
@@ -192,33 +192,33 @@ } | ||
switch (this.strategy) { | ||
case "migrate": | ||
return this.storage.start(this.id, this.contextSession).then((result) => { | ||
this.deSerialize(result); | ||
if (!this.isValidSession(result, this.context)) { | ||
this.manager.logger("INVALID SESSION ==> " + this.name + " : " + this.id, "WARNING"); | ||
this.destroy(); | ||
case "migrate": | ||
return this.storage.start(this.id, this.contextSession).then((result) => { | ||
this.deSerialize(result); | ||
if (!this.isValidSession(result, this.context)) { | ||
this.manager.logger("INVALID SESSION ==> " + this.name + " : " + this.id, "WARNING"); | ||
this.destroy(); | ||
this.contextSession = contextSession; | ||
return this.create(this.lifetime, null); | ||
} | ||
this.remove(); | ||
this.manager.logger(`STRATEGY MIGRATE SESSION ==> ${this.name} : ${this.id}`, "DEBUG"); | ||
this.migrated = true; | ||
this.contextSession = contextSession; | ||
return this.create(this.lifetime, null); | ||
} | ||
this.remove(); | ||
this.manager.logger(`STRATEGY MIGRATE SESSION ==> ${this.name} : ${this.id}`, "DEBUG"); | ||
this.migrated = true; | ||
}).catch((error) => { | ||
throw error; | ||
}); | ||
case "invalidate": | ||
this.manager.logger("STRATEGY INVALIDATE SESSION ==> " + this.name + " : " + this.id, "DEBUG"); | ||
this.destroy(); | ||
this.contextSession = contextSession; | ||
return this.create(this.lifetime, null); | ||
}).catch((error) => { | ||
throw error; | ||
}); | ||
case "invalidate": | ||
this.manager.logger("STRATEGY INVALIDATE SESSION ==> " + this.name + " : " + this.id, "DEBUG"); | ||
this.destroy(); | ||
this.contextSession = contextSession; | ||
return new Promise((resolve, reject) => { | ||
try { | ||
return resolve(this.create(this.lifetime, null)); | ||
} catch (e) { | ||
return reject(e); | ||
} | ||
}); | ||
case "none": | ||
this.strategyNone = true; | ||
break; | ||
return new Promise((resolve, reject) => { | ||
try { | ||
return resolve(this.create(this.lifetime, null)); | ||
} catch (e) { | ||
return reject(e); | ||
} | ||
}); | ||
case "none": | ||
this.strategyNone = true; | ||
break; | ||
} | ||
@@ -410,5 +410,5 @@ if (!this.strategyNone) { | ||
delete this.protoService; | ||
this.protoService = function () {}; | ||
this.protoService = function() {}; | ||
delete this.protoParameters; | ||
this.protoParameters = function () {}; | ||
this.protoParameters = function() {}; | ||
delete this.services; | ||
@@ -447,10 +447,10 @@ this.services = new this.protoService(); | ||
switch (this.settings.hash_function) { | ||
case "md5": | ||
hash = crypto.createHash('md5'); | ||
break; | ||
case "sha1": | ||
hash = crypto.createHash('sha1'); | ||
break; | ||
default: | ||
hash = crypto.createHash('md5'); | ||
case "md5": | ||
hash = crypto.createHash('md5'); | ||
break; | ||
case "sha1": | ||
hash = crypto.createHash('sha1'); | ||
break; | ||
default: | ||
hash = crypto.createHash('md5'); | ||
} | ||
@@ -457,0 +457,0 @@ let res = hash.update(concat).digest("hex"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
187456
43
4839
11
+ Addedrequest@^2.88.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)