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;

  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);
      while ((line = br.readLine()) != null) {
        parts = line.split("\\s*:\\s*");
        headers.put(parts[0], parts[1]);
      }
    } 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;
  }
}

@@ -352,16 +352,51 @@
 headers;
+%0A  final private String rawRequest;
 %0A%0A  publ
@@ -780,16 +780,60 @@
 g%3E(16);%0A
+      StringBuffer sb = new StringBuffer();%0A
       wh
@@ -867,24 +867,49 @@
  != null) %7B%0A
+        sb.append(line);%0A
         part
@@ -986,16 +986,50 @@
       %7D%0A
+      rawRequest = sb.toString();%0A
     %7D ca
@@ -1503,24 +1503,24 @@
 Headers() %7B%0A
-
     return h
@@ -1530,11 +1530,83 @@
 ers;%0A  %7D
+%0A%0A  public byte%5B%5D toByteBuffer() %7B%0A    return rawRequest.getBytes();%0A  %7D
 %0A%7D%0A

Add method to convert a `HttpRequest` to bytebuffer