-
Notifications
You must be signed in to change notification settings - Fork 1
/
http.js
42 lines (34 loc) · 1.06 KB
/
http.js
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
(function() {
module.exports.listen = function(host, port, emitter) {
var event = emitter;
var util = require("util");
var url = require("url");
var http = require("http");
http.createServer(function(request, response) {
request.extract_message = function() {
return(url.parse(this.url, true).query);
};
request.is_valid = function() {
try {
var query = this.extract_message();
if(typeof query.severity !== 'undefined' &&
typeof query.message !== 'undefined')
return(true);
else
return(false);
} catch(error) { return(false) }
};
if(!request.is_valid()) {
response.writeHead(400); // HTTP 400
response.end();
return;
}
response.writeHead(200); // HTTP 200 OK
response.end();
// emit message event
var message = request.extract_message();
event.emit("log", message);
}).listen(port, host);
util.puts("http capture listening on http://" host ":" port);
}
})();