Last active
December 4, 2016 06:23
-
-
Save wuyanxin/239209cecc99ca0a3edacce610b3dbdc to your computer and use it in GitHub Desktop.
A mini http-like server
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
const Server = require('./ihttp').Server; | |
const app = new Server().listen(3000); |
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
const net = require('net'); | |
const util = require('util'); | |
const debug = util.debuglog('ihttp'); | |
function Server() { | |
if (!(this instanceof Server)) return new Server(requestListener); | |
net.Server.call(this, { allowHalfOpen: true }); | |
this.addListener('connection', connectionListener); | |
} | |
util.inherits(Server, net.Server); | |
var counter = 0; | |
function connectionListener(socket) { | |
debug('new connection is coming', ++counter); | |
socket.on('data', function (chunk) { | |
debug('request'); | |
debug('chunk: ', chunk.toString('ascii', 0, chunk.length)); | |
}); | |
setTimeout(function () { | |
debug('response'); | |
socket.end('hello world'); | |
}, 1000); | |
} | |
module.exports = { | |
Server | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ignore http request headers
no http response headers