Placebo Effect
02 November 2009
Recently i was in need of a small webserver for embedded use in my ongoing irc project. I couldn’t seem to find a simple enough one to handle sessions/media. So i decided to start a small project called placebohttp.
![]()
Placebo is super simple
PlaceboHttpServer server = new PlaceboHttpServer(80);
server.start();
while (true)
{
// Blocks until request is made to http server.
HttpRequest request = server.getNextRequest();
HttpResponse response = new HttpResponse();
response.setContentType("text/html");
response.setData("<html><body><h1>Hello World</h1></body></html>")
request.sendResponse(response);
}
Handling sessions is just about as easy, however you do have to know a bit of threading. The server has another method known as getNextSession() which will block until a new user session is started. Once the first call to getNextSession() is made the server starts initializing sessions for all requests and directs all HttpRequest objects to the individual session object. The PlaceboSession object then has its own getNextRequest() method to handle incoming requests from that session. This is great if you want to treat each person accessing your website like a persistent connection.
Can i just play with it?
Placebo also has a standalone cli mode, nothing fancy just your basic webserver. However i did implement a cool feature where zip/jar/war files are treated like a normal file path.
so imagine you have a complete website zipped in fun.zip…
the following url would be valid http://localhost/fun.zip/index.html
To Download the latest build:
http://hg.openstatic.org/placebohttp/downloads/
Usage:
$ gij -jar placebohttp.jar --help
or
$ java -jar placebohttp.jar --help
I highly recommend the following method…
$ hg clone http://hg.openstatic.org/placebohttp $ cd placebohttp $ make $ ./placebohttp --help




