 
   def handle_packet(line, {app, buffer, conn}) do
     buffer = buffer <> line
-    decode_http_request(buffer)
-    case decode_http_request(buffer) do
+    decode_request(buffer)
+    case decode_request(buffer) do
       {:ok, request} ->
         {mod, state} = app
-        {:ok, {ip, port}} = conn
-        # request = %{request | port: port}
         mod.handle_request(request, state)
         case mod.handle_request(request, state) do
           %{body: body, headers: headers, status: status_code} ->
-            hl = Enum.map(headers, fn({x, y}) -> "#{x}: #{y}" end)
+            header_line = Enum.map(headers, fn({x, y}) -> "#{x}: #{y}" end)
             raw = [
               Raxx.Response.status_line(status_code),
-              Enum.join(hl, "\r\n"),
+              Enum.join(header_line, "\r\n"),
               "\r\n",
               "\r\n",
               body

        }}
    end
  end
  def decode_http_request(buffer) do
    decode_http_request(buffer, {:no_method, :no_path, :no_headers, :no_body})
  end
end

    IO.inspect(buffer)
  end

  def decode_headers(buffer) do
    decode_headers(buffer, [])
  end

  def decode_headers(buffer, headers) do
    case :erlang.decode_packet(:httph_bin, buffer, []) do
      {:ok, {:http_header, _, key, _, value}, rest} ->
        headers = headers ++ [{key, value}]
        decode_headers(rest, headers)
      {:ok, :http_eoh, rest} ->
        {:ok, headers, rest}
    end
  end

  def decode_request(buffer) do
    case :erlang.decode_packet(:http_bin, buffer, []) do
      {:ok, {:http_request, method, {:abs_path, path_string}, _version}, rest} ->
        {path, query} = Raxx.Request.parse_path(path_string)

        {:ok, headers, body} = decode_headers(rest)

        {:Host, authority} = headers |> List.keyfind(:Host, 0)
        [host, port] = String.split(authority, ":")
        
        {:ok, %Raxx.Request{
          host: host,
          port: :erlang.binary_to_integer(port),
