Last active
December 10, 2015 17:28
-
-
Save jonatw/4468299 to your computer and use it in GitHub Desktop.
nodejs practice #1 with native http object
This file contains hidden or 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 practice is base on this documents http://nodejs.org/api/http.html#http_request_connection | |
var server, | |
ip = "192.168.1.12", | |
port = 1337, | |
http = require('http'); | |
server = http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
console.log("========== syslog ========== \n"+req.method+"\n"+req.url+"\n"); | |
// debug headers | |
for( var header_data_index in req.headers){ | |
console.log("http header #"+header_data_index+" : "+req.headers[header_data_index]+"\n"); | |
} | |
//debug trailser | |
for( var trailer_data_index in req.trailers){ | |
console.log("http trailer #"+trailer_data_index+" : "+req.trailers[trailer_data_index]+"\n"); | |
} | |
console.log("httpVersionMajo : "+req.httpVersionMajo+"\n"); | |
//debug connection | |
for( var connection_data_index in req.connection){ | |
console.log("http connection #"+connection_data_index+" : "+req.connection[connection_data_index]+"\n"); | |
} | |
}); | |
server.listen(port, ip); | |
console.log("Server running at http://" + ip + ":" + port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment