mafintosh / turbo-http

Blazing fast low level http server
MIT License
1k stars 47 forks source link

Allows Subclassing of Request, Response, Server #10

Closed santoshrajan closed 6 years ago

santoshrajan commented 6 years ago

Currently Request, Response, Server, is not subclassable. Servers using turbo-http need to monkey patch req and res objects. This pull request fixes that. This will allow hidden class optimisations of V8. All parsing and buffer reuse code has been moved to the Request Class. Server object is required when you create a request.

Example Usage.

const turbo = require('turbo-http')

class Request extends turbo.Request {
}

class Response extends turbo.Response {
}

class Server extends turbo.Server {
  _onhttpconnection (socket) {
     const req = new Request(this, socket)
     const res = new Response(this, socket, req)
     req.onhead = () => this.emit('request', req, res)
  }
}
santoshrajan commented 6 years ago

Have to rewrite this.

santoshrajan commented 6 years ago

Have to rewrite this.