package org.yukung.sandbox.http;

import static org.yukung.sandbox.http.HttpRequest.CRLF;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author yukung
 */
public class Main {
    public static void main(String[] args) throws IOException {
        System.out.println("start >>>");

        try (
            ServerSocket ss = new ServerSocket(8080);
            Socket socket = ss.accept();
            InputStream in = socket.getInputStream();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()))
        ) {
            HttpRequest request = new HttpRequest(in);

            System.out.println(request.getHeaderText());
            System.out.println(request.getBodyText());

            bw.write("HTTP/1.1 200 OK" + CRLF);
        }

        System.out.println("<<< end");
    }
}

@@ -77,20 +77,17 @@
 Request.
-CRLF
+*
 ;%0A%0Aimpor
@@ -903,16 +903,147 @@
  CRLF);%0A
+            bw.write(%22Content-Type: text/html%22 + CRLF);%0A            bw.write(CRLF);%0A            bw.write(%22%3Ch1%3EHello World!%3C/h1%3E%22);%0A
         

Return the simple response header and response body.