-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
48 lines (38 loc) · 1.13 KB
/
utils.js
File metadata and controls
48 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
/**
* Checks if a request is parseable by formidable
*
* @param {obj} req - standard request object
* @returns {bool} - true or false
*/
function formidableParseable(req) {
// For reference this is taken from formidable/lib/incoming_form.js - IncomingForm.prototype._parseContentType definition
if (req.method !== 'POST') {
return false;
}
// Make sure to pick up content type header case insensitive
for (const key of Object.keys(req.headers)) {
if (key.toLowerCase() === 'content-type' && req.headers['content-type'] === undefined) {
req.headers['content-type'] = req.headers[key];
break;
}
}
if (!req.headers['content-type']) {
return false;
}
if (req.headers['content-type'].match(/octet-stream/i)) {
return true;
}
if (req.headers['content-type'].match(/urlencoded/i)) {
return true;
}
if (req.headers['content-type'].match(/multipart/i) && req.headers['content-type'].match(/boundary=(?:"([^"]+)"|([^;]+))/i)) {
return true;
}
if (req.headers['content-type'].match(/json/i)) {
return true;
}
// No matches
return false;
};
exports.formidableParseable = formidableParseable;