import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 * Created by Xinan on 15/9/15.
 */
public class HttpRequest {

  final private String method;
  final private String url;
  final private String httpVersion;
  final private HashMap<String, String> headers;
  final private String rawRequest;

  public HttpRequest(InputStream clientInputStream) throws IOException, MalformedRequestException {
    try (BufferedReader br = new BufferedReader(new InputStreamReader(clientInputStream))) {
      String line;
      String[] parts = br.readLine().split("\\s+");
      method = parts[0];
      url = parts[1];
      httpVersion = parts[2];

      headers = new HashMap<String, String>(16);
      StringBuffer sb = new StringBuffer();
      while ((line = br.readLine()) != null) {
        sb.append(line);
        parts = line.split("\\s*:\\s*");
        headers.put(parts[0], parts[1]);
      }
      rawRequest = sb.toString();
    } catch (IOException e) {
      System.out.printf("Exception in HttpRequest: %s\n", e.getMessage());
      throw e;
    } catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
      throw new MalformedRequestException("Invalid request format!");
    }
  }

  public String getMethod() {
    return method;
  }

  public String getUrl() {
    return url;
  }

  public String getHttpVersion() {
    return httpVersion;
  }

  public HashMap<String, String> getHeaders() {
    return headers;
  }

  public byte[] toByteBuffer() {
    return rawRequest.getBytes();
  }
}

@@ -497,17 +497,24 @@
     try 
-(
+%7B%0A      
 Buffered
@@ -585,19 +585,17 @@
 Stream))
-) %7B
+;
 %0A      S
@@ -622,32 +622,96 @@
 ring
-%5B%5D parts = br.readLine()
+Buffer sb = new StringBuffer();%0A%0A      line = br.readLine();%0A      String%5B%5D parts = line
 .spl
@@ -797,16 +797,68 @@
 parts%5B2%5D
+.split(%22/%22)%5B1%5D;%0A      sb.append(line).append(%22%5Cr%5Cn%22)
 ;%0A%0A     
@@ -905,52 +905,8 @@
 6);%0A
-      StringBuffer sb = new StringBuffer();%0A
     
@@ -948,36 +948,37 @@
 null
-) %7B%0A        sb.append(line);
+ && !line.trim().isEmpty()) %7B
 %0A   
@@ -1062,17 +1062,207 @@
 ;%0A      
-%7D
+  if (parts%5B0%5D.equals(%22Connection%22)) %7B%0A          continue; // Do not keep-alive.%0A        %7D%0A        sb.append(line).append(%22%5Cr%5Cn%22);%0A      %7D%0A      sb.append(%22%5Cr%5Cn%22); // Indicate end of request.
 %0A      r
@@ -1813,64 +1813,186 @@
 lic 
-byte%5B%5D toByteBuffer() %7B%0A    return rawRequest.getBytes()
+String getHost() %7B%0A    return headers.get(%22Host%22);%0A  %7D%0A%0A  public byte%5B%5D toByteBuffer() %7B%0A    return rawRequest.getBytes();%0A  %7D%0A%0A  public String toString() %7B%0A    return rawRequest
 ;%0A  

Fix `HttpRequest`