// Copyright 2014, Kevin Ko <kevin@faveset.com>

package com.faveset.khttpserver;

import java.io.IOException;
import sun.misc.Signal;
import sun.misc.SignalHandler;

import com.faveset.log.OutputStreamLog;

public class HttpServer {
    public static void main(String[] args) throws IOException {
        if (args.length < 1) {
            System.out.println("<port>");
            return;
        }

        int port = new Integer(args[0]);

        OutputStreamLog log = new OutputStreamLog(System.out);

        final com.faveset.khttp.HttpServer server = new com.faveset.khttp.HttpServer();
        server.setLog(log);

        // Set up the signal handler.
        Signal.handle(new Signal("INT"), new SignalHandler() {
            @Override
            public void handle(Signal sig) {
                server.stop();
            }
        });
        server.listenAndServe("::", port);

        log.close();
    }
}

@@ -156,24 +156,146 @@
 alHandler;%0A%0A
+import com.faveset.khttp.HttpHandler;%0Aimport com.faveset.khttp.HttpRequest;%0Aimport com.faveset.khttp.HttpResponseWriter;%0A%0A
 import com.f
@@ -322,16 +322,16 @@
 eamLog;%0A
-
 %0Apublic 
@@ -776,16 +776,39 @@
  handler
+ for exiting the server
 .%0A      
@@ -927,24 +927,24 @@
 gnal sig) %7B%0A
-
             
@@ -987,16 +987,337 @@
      %7D);
+%0A%0A        // Register handlers.%0A%0A        server.registerHandler(%22/%22, new HttpHandler() %7B%0A            public void onRequest(HttpRequest req, HttpResponseWriter w) %7B%0A                w.getHeadersBuilder().set(%22Content-Type%22, %22text/html%22);%0A                w.write(%22%3Chtml%3E%3Cbody%3EHello%3C/body%3E%3C/html%3E%22);%0A            %7D%0A        %7D);
 %0A       

Add simple handler for demonstrating usage.