New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nodefony/http-bundle

Package Overview
Dependencies
Maintainers
1
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodefony/http-bundle - npm Package Compare versions

Comparing version 5.0.9 to 5.1.0

2

package.json
{
"name": "@nodefony/http-bundle",
"version": "5.0.9",
"version": "5.1.0",
"description": "Nodefony Framework Bundle HTTP ",

@@ -5,0 +5,0 @@ "contributors": [],

@@ -80,32 +80,32 @@ /*

switch (nodefony.typeOf(this.kernel.domainAlias)) {
case "string":
alias = this.kernel.domainAlias.split(" ");
Array.prototype.unshift.call(alias, "^" + this.kernel.domain + "$");
for (let i = 0; i < alias.length; i++) {
if (i === 0) {
str = alias[i];
} else {
str += "|" + alias[i];
}
case "string":
alias = this.kernel.domainAlias.split(" ");
Array.prototype.unshift.call(alias, "^" + this.kernel.domain + "$");
for (let i = 0; i < alias.length; i++) {
if (i === 0) {
str = alias[i];
} else {
str += "|" + alias[i];
}
break;
case "object":
let first = true;
for (let myAlias in this.kernel.domainAlias) {
if (first) {
first = false;
str = this.kernel.domainAlias[myAlias];
} else {
str += "|" + this.kernel.domainAlias[myAlias];
}
}
break;
case "object":
let first = true;
for (let myAlias in this.kernel.domainAlias) {
if (first) {
first = false;
str = this.kernel.domainAlias[myAlias];
} else {
str += "|" + this.kernel.domainAlias[myAlias];
}
break;
case "array":
str = "^" + this.kernel.domain + "$";
for (let i = 0; i < this.kernel.domainAlias.length; i++) {
str += "|" + this.kernel.domainAlias[i];
}
break;
default:
throw new Error("Config file bad format for domain alias must be a string ");
}
break;
case "array":
str = "^" + this.kernel.domain + "$";
for (let i = 0; i < this.kernel.domainAlias.length; i++) {
str += "|" + this.kernel.domainAlias[i];
}
break;
default:
throw new Error("Config file bad format for domain alias must be a string ");
}

@@ -199,3 +199,6 @@ if (str) {

extendTemplate(param, context) {
return nodefony.extend({}, param, {
if (param && typeof param !== "object") {
throw new Error(`bad paramaters template ${param} must be an object`);
}
return nodefony.extend(param, {
nodefony: {

@@ -232,2 +235,34 @@ name: nodefony.projectName,

});
/*param.nodefony = {
name: nodefony.projectName,
version: nodefony.version,
projectVersion: nodefony.projectVersion,
url: context.request.url,
environment: this.kernel.environment,
debug: this.kernel.debug,
local: context.translation.defaultLocale.substr(0, 2),
core: this.kernel.isCore
};
param.getFlashBag = context.getFlashBag.bind(context);
param.render = context.render.bind(context);
param.controller = context.controller.bind(context);
param.trans = context.translation.trans.bind(context.translation);
param.getLocale = context.translation.getLocale.bind(context.translation);
param.trans_default_domain = context.translation.trans_default_domain.bind(context.translation);
param.getTransDefaultDomain = context.translation.getTransDefaultDomain.bind(context.translation);
param.getUser = context.getUser.bind(context);
param.CDN = (type, nb) => {
let cdn = this.getCDN(type, nb);
let res = `${context.request.url.protocol}//`;
if (cdn) {
return `${res}${cdn}`;
} else {
return `${res}${context.request.url.host}`;
}
};
param.absolute_url = context.generateAbsoluteUrl.bind(context);
param.is_granted = context.is_granted.bind(context);
return param;*/
}

@@ -258,26 +293,26 @@

switch (typeof this.cdn) {
case "object":
if (!this.cdn) {
return "";
}
if (this.cdn.global) {
return this.cdn.global;
}
if (!type) {
let txt = "CDN ERROR getCDN bad argument type ";
this.logger(txt, "ERROR");
throw new Error(txt);
}
if (type in this.cdn) {
if (this.cdn[type][wish]) {
return this.cdn[type][wish];
}
}
case "object":
if (!this.cdn) {
return "";
case "string":
return this.cdn || "";
default:
let txt = "CDN CONFIG ERROR ";
}
if (this.cdn.global) {
return this.cdn.global;
}
if (!type) {
let txt = "CDN ERROR getCDN bad argument type ";
this.logger(txt, "ERROR");
throw new Error(txt);
}
if (type in this.cdn) {
if (this.cdn[type][wish]) {
return this.cdn[type][wish];
}
}
return "";
case "string":
return this.cdn || "";
default:
let txt = "CDN CONFIG ERROR ";
this.logger(txt, "ERROR");
throw new Error(txt);
}

@@ -294,21 +329,21 @@ }

switch (next) {
case 200:
return next;
default:
this.logger("\x1b[31m DOMAIN Unauthorized \x1b[0mREQUEST DOMAIN : " + context.domain, "ERROR");
let error = new Error("Domain : " + context.domain + " Unauthorized ");
error.code = next;
throw error;
/*switch ( context.type ){
case "HTTP":
case "HTTPS":
this.logger("\x1b[31m DOMAIN Unauthorized \x1b[0mREQUEST DOMAIN : " + context.domain ,"ERROR");
let error = new Error("Domain : "+context.domain+" Unauthorized ");
error.code = next ;
throw error ;
case "WEBSOCKET":
case "WEBSOCKET SECURE":
context.close(3001, "DOMAIN Unauthorized "+ context.domain );
break;
}*/
case 200:
return next;
default:
this.logger("\x1b[31m DOMAIN Unauthorized \x1b[0mREQUEST DOMAIN : " + context.domain, "ERROR");
let error = new Error("Domain : " + context.domain + " Unauthorized ");
error.code = next;
throw error;
/*switch ( context.type ){
case "HTTP":
case "HTTPS":
this.logger("\x1b[31m DOMAIN Unauthorized \x1b[0mREQUEST DOMAIN : " + context.domain ,"ERROR");
let error = new Error("Domain : "+context.domain+" Unauthorized ");
error.code = next ;
throw error ;
case "WEBSOCKET":
case "WEBSOCKET SECURE":
context.close(3001, "DOMAIN Unauthorized "+ context.domain );
break;
}*/
}

@@ -324,12 +359,12 @@ return next;

switch (true) {
case (error instanceof nodefony.securityError):
case (error instanceof nodefony.httpError):
httpError = error;
break;
default:
if (context.response && context.response.statusCode === 200) {
httpError = new nodefony.httpError(error, 500, container);
} else {
httpError = new nodefony.httpError(error, null, container);
}
case (error instanceof nodefony.securityError):
case (error instanceof nodefony.httpError):
httpError = error;
break;
default:
if (context.response && context.response.statusCode === 200) {
httpError = new nodefony.httpError(error, 500, container);
} else {
httpError = new nodefony.httpError(error, null, container);
}
}

@@ -391,5 +426,5 @@ if (!httpError.context) {

return this.handle(request, response, type)
.catch(e => {
this.logger(e, "ERROR");
});
.catch(e => {
this.logger(e, "ERROR");
});
}

@@ -415,9 +450,9 @@ throw new Error("Bad request");

switch (type) {
case "HTTP":
case "HTTPS":
case "HTTP2":
return this.handleHttp(container, request, response, type);
case "WEBSOCKET":
case "WEBSOCKET SECURE":
return this.handleWebsocket(container, request, type);
case "HTTP":
case "HTTPS":
case "HTTP2":
return this.handleHttp(container, request, response, type);
case "WEBSOCKET":
case "WEBSOCKET SECURE":
return this.handleWebsocket(container, request, type);
}

@@ -463,10 +498,25 @@ }

// FRONT ROUTER
let resolver = this.router.resolve(context);
if (resolver.resolve) {
context.resolver = resolver;
controller = resolver.newController(context.container, context);
if (controller.sessionAutoStart) {
context.sessionAutoStart = controller.sessionAutoStart;
if (context.csrf) {
context.once("onSessionStart", () => {
try {
let resolver = this.router.resolve(context);
if (resolver.resolve) {
context.resolver = resolver;
controller = resolver.newController(context.container, context);
if (controller.sessionAutoStart) {
context.sessionAutoStart = controller.sessionAutoStart;
if (context.csrf) {
context.once("onSessionStart", () => {
return this.csrfService.handle(context)
.then((token) => {
if (token) {
this.logger(`Check CSRF TOKEN : ${token.name} OK`);
}
return resolve(controller);
})
.catch(e => {
return reject(e);
});
});
}
} else {
if (context.csrf) {
return this.csrfService.handle(context)

@@ -482,23 +532,12 @@ .then((token) => {

});
});
}
}
} else {
if (context.csrf) {
return this.csrfService.handle(context)
.then((token) => {
if (token) {
this.logger(`Check CSRF TOKEN : ${token.name} OK`);
}
return resolve(controller);
})
.catch(e => {
return reject(e);
});
}
return resolve(controller);
}
return resolve(controller);
let error = new Error("Not Found");
error.code = 404;
return reject(error);
} catch (e) {
return reject(e);
}
let error = new Error("Not Found");
error.code = 404;
return reject(error);
});

@@ -539,8 +578,8 @@ }

return this.firewall.handleSecurity(context)
.then(()=>{
return resolve(null);
})
.catch(e =>{
return reject(e);
});
.then(() => {
return resolve(null);
})
.catch(e => {
return reject(e);
});
//return resolve(this.firewall.handleSecurity(context));

@@ -608,3 +647,3 @@ }

.then((ctx) => {
if ( ctx instanceof nodefony.Context){
if (ctx instanceof nodefony.Context) {
return ctx.handle()

@@ -743,2 +782,2 @@ .then(() => {

};
};

@@ -169,3 +169,3 @@ nodefony.register.call(nodefony.context, "http", function() {

clean() {
clean() {
if (this.timeoutid !== null) {

@@ -172,0 +172,0 @@ clearTimeout(this.timeoutid);

const QS = require('qs');
const formidable = require("formidable");
module.exports = nodefony.register("Request", function () {
module.exports = nodefony.register("Request", function() {

@@ -10,3 +10,3 @@ // ARRAY PHP LIKE

const parser = class parser {
class Parser {
constructor(request) {

@@ -17,5 +17,2 @@ this.request = request;

});
this.request.request.on("end", () => {
this.parse();
});
}

@@ -33,7 +30,6 @@ write(buffer) {

this.request.context.requestEnded = true;
this.request.context.fire("onRequestEnd", this.request);
}
};
}
const parserQs = class parserQs extends parser {
class ParserQs extends Parser {
constructor(request) {

@@ -55,5 +51,5 @@ super(request);

}
};
}
const parserXml = class parserXml extends parser {
class ParserXml extends Parser {
constructor(request) {

@@ -74,5 +70,5 @@ super(request);

}
};
}
const acceptParser = function (acc) {
const acceptParser = function(acc) {
if (!acc) {

@@ -182,19 +178,56 @@ return [{

});
try {
if (this.method in parse) {
this.parserRequest();
} else {
this.request.on("end", () => {
this.context.requestEnded = true;
this.context.fire("onRequestEnd", this);
});
}
} catch (error) {
this.request.on("end", () => {
this.context.requestEnded = true;
this.context.fire("onError", this.context.container, error);
this.parseRequest()
.then((parser) => {
switch (true) {
case parser instanceof Parser:
case parser instanceof ParserQs:
case parser instanceof ParserXml:
this.request.once("end", () => {
if (this.context.finished) {
return;
}
parser.parse();
this.context.fire("onRequestEnd", this);
});
break;
default:
if (! parser) {
this.request.once("end", () => {
if (this.context.finished) {
return;
}
this.context.requestEnded = true;
this.context.fire("onRequestEnd", this);
});
}
}
return parser;
})
.catch((error) => {
if (this.context.requestEnded) {
this.context.fire("onError", this.context.container, error);
} else {
this.request.once("end", () => {
this.context.requestEnded = true;
this.context.fire("onError", this.context.container, error);
});
}
});
}
}
parseRequest() {
return new Promise((resolve, reject) => {
try {
if (this.method in parse) {
return resolve(this.parserRequest());
} else {
return resolve();
}
} catch (error) {
return reject(error);
}
});
}
createFileUpload(name, file, maxSize) {

@@ -215,62 +248,63 @@ if (file.size > maxSize) {

switch (this.contentType) {
case "application/xml":
case "text/xml":
this.parser = new parserXml(this);
break;
case "application/x-www-form-urlencoded":
this.parser = new parserQs(this);
break;
default:
let opt = nodefony.extend(this.context.requestSettings, {
encoding: this.charset
});
this.parser = new formidable.IncomingForm(opt);
this.parser.parse(this.request, (err, fields, files) => {
if (err) {
this.request.on("end", () => {
this.context.fire("onError", this.context.container, err);
});
return;
}
try {
this.queryPost = fields;
//this.context.setParameters("query.post", this.queryPost);
this.query = nodefony.extend({}, this.query, this.queryPost);
//this.context.setParameters("query.request", this.query);
if (Object.keys(files).length) {
for (let file in files) {
try {
if (reg.exec(file)) {
if (nodefony.isArray(files[file])) {
for (let multifiles in files[file]) {
this.createFileUpload(multifiles, files[file][multifiles], opt.maxFileSize);
case "application/xml":
case "text/xml":
this.parser = new ParserXml(this);
return this.parser;
case "application/x-www-form-urlencoded":
this.parser = new ParserQs(this);
return this.parser;
default:
let opt = nodefony.extend(this.context.requestSettings, {
encoding: this.charset
});
this.parser = new formidable.IncomingForm(opt);
this.parser.parse(this.request, (err, fields, files) => {
if (err) {
this.request.on("end", () => {
this.context.fire("onError", this.context.container, err);
});
return;
}
try {
this.queryPost = fields;
//this.context.setParameters("query.post", this.queryPost);
this.query = nodefony.extend({}, this.query, this.queryPost);
//this.context.setParameters("query.request", this.query);
if (Object.keys(files).length) {
for (let file in files) {
try {
if (reg.exec(file)) {
if (nodefony.isArray(files[file])) {
for (let multifiles in files[file]) {
this.createFileUpload(multifiles, files[file][multifiles], opt.maxFileSize);
}
} else {
if (files[file].name) {
this.createFileUpload(file, files[file], opt.maxFileSize);
}
}
} else {
if (files[file].name) {
if (nodefony.isArray(files[file])) {
for (let multifiles in files[file]) {
this.createFileUpload(multifiles, files[file][multifiles], opt.maxFileSize);
}
} else {
this.createFileUpload(file, files[file], opt.maxFileSize);
}
}
} else {
if (nodefony.isArray(files[file])) {
for (let multifiles in files[file]) {
this.createFileUpload(multifiles, files[file][multifiles], opt.maxFileSize);
}
} else {
this.createFileUpload(file, files[file], opt.maxFileSize);
}
} catch (err) {
this.context.fire("onError", this.context.container, err);
return err;
}
} catch (err) {
this.context.fire("onError", this.context.container, err);
return err;
}
}
} catch (err) {
this.request.on("end", () => {
this.context.fire("onError", this.context.container, err);
});
}
} catch (err) {
this.request.on("end", () => {
this.context.fire("onError", this.context.container, err);
});
}
this.context.requestEnded = true;
this.context.fire("onRequestEnd", this);
});
this.context.requestEnded = true;
this.context.fire("onRequestEnd", this);
});
return this.parser;
}

@@ -289,11 +323,11 @@ }

switch (parse.length) {
case 1:
subtype = parse.shift();
break;
case 2:
type = parse.shift();
subtype = parse.shift();
break;
default:
throw new Error("request accepts method bad type format");
case 1:
subtype = parse.shift();
break;
case 2:
type = parse.shift();
subtype = parse.shift();
break;
default:
throw new Error("request accepts method bad type format");
}

@@ -455,2 +489,2 @@ }

return Request;
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc