Basil
Middleware oriented proxy
About
Basil is a simple but extendable proxy. It makes easy for developers to alter requests and responses. Basil has no such thing as configuration file or a command line program. Requests and Responses can be modified by inserting logical handlers.
Examples
1. Simple "full copy"
var basil = ;var app = ; app;
2. Log all the requests
var basil = ;var app = ; app; app;
3. Log all the responses
var basil = ;var app = ; app; app;
4. Always return a 404 code
var basil = ;var app = ; app; app;
What's the bundle object ?
As you see, your functions are called for each requests and responses. Everytime you'll get a bundle object.
Here is its structure :
- bundle.request : the options object you usually give to http.request
- bundle.request.headers : An object model of the HTTP headers the client sent.
- bundle.request.body : the Buffer object of the request body (normally in POST requests).
In case you are response side you'll get :
- bundle.response.status : The status code that will be returned
- bundle.response.headers : An object model of the HTTP headers the client will receive.
- bundle.response.body : the Buffer object of the returned data.
In the bundle object, everything can be read/written.