@nodefony/http-bundle
Advanced tools
Comparing version 6.0.0-beta.7 to 6.0.0-beta.8
{ | ||
"name": "@nodefony/http-bundle", | ||
"version": "6.0.0-beta.7", | ||
"version": "6.0.0-beta.8", | ||
"description": "Nodefony Framework Bundle HTTP ", | ||
@@ -19,5 +19,5 @@ "contributors": [], | ||
"mime": "^2.4.4", | ||
"mkdirp": "^1.0.3", | ||
"mkdirp": "^1.0.4", | ||
"ms": "^2.1.2", | ||
"qs": "^6.9.2", | ||
"qs": "^6.9.3", | ||
"request": "^2.88.2", | ||
@@ -24,0 +24,0 @@ "serve-static": "^1.14.1", |
@@ -180,3 +180,7 @@ const QS = require('qs'); | ||
}); | ||
this.parseRequest() | ||
this.initialize(); | ||
} | ||
initialize(){ | ||
return this.parseRequest() | ||
.then((parser) => { | ||
@@ -193,3 +197,3 @@ switch (true) { | ||
parser.parse(); | ||
this.context.fire("onRequestEnd", this); | ||
return this.context.fireAsync("onRequestEnd", this); | ||
} catch (error) { | ||
@@ -202,3 +206,3 @@ return this.context.kernelHttp.onError(this.context.container, error); | ||
if (!parser) { | ||
this.request.once("end", () => { | ||
this.request.once("end",() => { | ||
try { | ||
@@ -209,3 +213,3 @@ if (this.context.finished) { | ||
this.context.requestEnded = true; | ||
this.context.fire("onRequestEnd", this); | ||
return this.context.fireAsync("onRequestEnd", this); | ||
} catch (error) { | ||
@@ -221,3 +225,2 @@ return this.context.kernelHttp.onError(this.context.container, error); | ||
if (this.context.requestEnded) { | ||
//this.context.fire("onError", this.context.container, error); | ||
return this.context.kernelHttp.onError(this.context.container, error); | ||
@@ -227,3 +230,2 @@ } else { | ||
this.context.requestEnded = true; | ||
//this.context.fire("onError", this.context.container, error); | ||
return this.context.kernelHttp.onError(this.context.container, error); | ||
@@ -237,10 +239,64 @@ }); | ||
return new Promise((resolve, reject) => { | ||
try { | ||
if (this.method in parse) { | ||
return resolve(this.parserRequest()); | ||
} else { | ||
return resolve(); | ||
if (this.method in parse) { | ||
switch (this.contentType) { | ||
case "application/xml": | ||
case "text/xml": | ||
this.parser = new ParserXml(this); | ||
return resolve(this.parser); | ||
case "application/x-www-form-urlencoded": | ||
try { | ||
this.parser = new ParserQs(this); | ||
} catch (e) { | ||
return reject(e); | ||
} | ||
return resolve(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) { | ||
return reject(err); | ||
} | ||
try { | ||
this.queryPost = fields; | ||
this.query = nodefony.extend({}, this.query, this.queryPost); | ||
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 (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) { | ||
return reject(err); | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
return reject(err); | ||
} | ||
this.context.requestEnded = true; | ||
this.context.fireAsync("onRequestEnd", this); | ||
return resolve(this.parser); | ||
}); | ||
} | ||
} catch (error) { | ||
return reject(error); | ||
} else { | ||
return resolve(); | ||
} | ||
@@ -263,76 +319,2 @@ }); | ||
parserRequest() { | ||
switch (this.contentType) { | ||
case "application/xml": | ||
case "text/xml": | ||
this.parser = new ParserXml(this); | ||
return this.parser; | ||
case "application/x-www-form-urlencoded": | ||
try { | ||
this.parser = new ParserQs(this); | ||
} catch (e) { | ||
throw e; | ||
} | ||
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 this.context.kernelHttp.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 (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 this.context.kernelHttp.onError(this.context.container, err); | ||
//return err; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
this.request.on("end", () => { | ||
//this.context.fire("onError", this.context.container, err); | ||
return this.context.kernelHttp.onError(this.context.container, err); | ||
}); | ||
return; | ||
} | ||
this.context.requestEnded = true; | ||
this.context.fire("onRequestEnd", this); | ||
}); | ||
return this.parser; | ||
} | ||
} | ||
accepts(Type) { | ||
@@ -513,2 +495,2 @@ let parse = null; | ||
return Request; | ||
}); | ||
}); |
179940
5303
Updatedmkdirp@^1.0.4
Updatedqs@^6.9.3