-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessPost.js
More file actions
30 lines (25 loc) · 835 Bytes
/
processPost.js
File metadata and controls
30 lines (25 loc) · 835 Bytes
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
var http = require("http");
var qs = require("querystring");
function processPost(request, response, callback) {
var queryData = "";
if (typeof callback !== "function") return null;
if (request.method == "POST") {
request.on("data", function(data) {
queryData += data;
if (queryData.length > 1e6) {
queryData = "";
response.writeHead(415, {"Content-Type": "text/plain"});
response.end();
request.connection.destroy();
}
});
request.on("end", function() {
response.post = qs.parse(queryData);
callback(response);
});
} else {
response.writeHead(405, {"Content-Type": "text/plain"});
response.end();
}
}
exports.processPost = processPost;