-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 End requests with an error when parsing posted body contents fail
- Loading branch information
Showing
3 changed files
with
59 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1750,7 +1750,7 @@ Alchemy.setMethod(function addAppcacheEntry(entry) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.1.0 | ||
* @version 1.3.18 | ||
* @version 1.4.0 | ||
* | ||
* @param {IncomingMessage} req | ||
* @param {OutgoingMessage} res Optional | ||
|
@@ -1787,14 +1787,24 @@ Alchemy.setMethod(function parseRequestBody(req, res, callback) { | |
|
||
form.parse(req, function parsedMultipart(err, form_fields, form_files) { | ||
|
||
var fields = {}, | ||
files = {}, | ||
key; | ||
if (err) { | ||
|
||
if (err && req.conduit && req.conduit.aborted) { | ||
return callback(null); | ||
// Ignore the error if the request was already aborted | ||
if (conduit?.aborted) { | ||
return callback(null); | ||
} | ||
|
||
if (conduit) { | ||
return conduit.error(err); | ||
} | ||
|
||
return callback(err); | ||
} | ||
|
||
let fields = {}, | ||
files = {}, | ||
key; | ||
|
||
// Since formidable v3, all the fields are now arrays. | ||
// We already had a lot of logic to deal with this, | ||
// so we just have to un-array everything | ||
|
@@ -1811,18 +1821,12 @@ Alchemy.setMethod(function parseRequestBody(req, res, callback) { | |
Object.setFormPath(files, key, form_files[key]); | ||
} | ||
|
||
if (err) { | ||
log.error('Error parsing multipart POST', {err: err}); | ||
req.body = {}; | ||
req.files = {}; | ||
} else { | ||
req.body = fields; | ||
req.files = files; | ||
req.body = fields; | ||
req.files = files; | ||
|
||
if (conduit) { | ||
conduit.setRequestBody(fields); | ||
conduit.setRequestFiles(files); | ||
} | ||
if (conduit) { | ||
conduit.setRequestBody(fields); | ||
conduit.setRequestFiles(files); | ||
} | ||
|
||
callback(null, fields); | ||
|
@@ -1836,22 +1840,27 @@ Alchemy.setMethod(function parseRequestBody(req, res, callback) { | |
|
||
this.url_form_body(req, res, function parsedBody(err) { | ||
|
||
if (err && req.conduit && req.conduit.aborted) { | ||
return callback(null); | ||
if (err) { | ||
|
||
// Ignore the error if the request was already aborted | ||
if (conduit?.aborted) { | ||
return callback(null); | ||
} | ||
|
||
if (conduit) { | ||
return conduit.error(err); | ||
} | ||
|
||
return callback(err); | ||
} | ||
|
||
// You can't send files using a regular post | ||
req.files = {}; | ||
|
||
if (err) { | ||
log.error('Error parsing x-www-form-urlencoded body data', {err: err}); | ||
req.body = {}; | ||
} else { | ||
req.body = req.body; | ||
req.body = req.body; | ||
|
||
if (conduit) { | ||
conduit.setRequestBody(req.body); | ||
} | ||
if (conduit) { | ||
conduit.setRequestBody(req.body); | ||
} | ||
|
||
callback(null, req.body); | ||
|
@@ -1861,25 +1870,30 @@ Alchemy.setMethod(function parseRequestBody(req, res, callback) { | |
} | ||
|
||
// Any other encoded data (like JSON) | ||
this.any_body(req, function parsedBody(err, body) { | ||
this.any_body(req, res, function parsedBody(err, body) { | ||
|
||
function handleResponse(err, body) { | ||
if (err && req.conduit && req.conduit.aborted) { | ||
return callback(null); | ||
|
||
if (err) { | ||
|
||
// Ignore the error if the request was already aborted | ||
if (conduit?.aborted) { | ||
return callback(null); | ||
} | ||
|
||
if (conduit) { | ||
return conduit.error(err); | ||
} | ||
|
||
return callback(err); | ||
} | ||
|
||
// You can't send files using a regular post | ||
req.files = {}; | ||
req.body = body; | ||
|
||
if (err) { | ||
log.error('Error parsing body data', {err: err}); | ||
req.body = {}; | ||
} else { | ||
req.body = body; | ||
|
||
if (conduit) { | ||
conduit.setRequestBody(body); | ||
} | ||
if (conduit) { | ||
conduit.setRequestBody(body); | ||
} | ||
|
||
callback(null, req.body); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "alchemymvc", | ||
"description": "MVC framework for Node.js", | ||
"version": "1.4.0-alpha.6", | ||
"version": "1.4.0-alpha.7", | ||
"author": "Jelle De Loecker <[email protected]>", | ||
"keywords": [ | ||
"alchemy", | ||
|