           bytes ->
             {headers, true, {:bytes, bytes}}
         end
+    end
+  end
+
+  defp decode_connection_status(headers) do
+    case Enum.split_with(headers, fn {key, _value} -> key == "connection" end) do
+      {[{"connection", "close"}], headers} ->
+        {:close, headers}
+
+      {[{"connection", "keep-alive"}], headers} ->
+        {:keepalive, headers}
+
+      {[], headers} ->
+        {nil, headers}
     end
   end
 

         query: "qs",
         raw_path: "/path",
         scheme: :http
       }, {:complete, ""}, ""}

      iex> "GET /path?qs HTTP/1.1\\r\\nhost: example.com\\r\\naccept: text/plain\\r\\n\\r\\n"
      ...> |> Raxx.HTTP1.parse_request(:https)
      {:ok,
       %Raxx.Request{
         authority: "example.com",
         body: false,
         headers: [{"accept", "text/plain"}],

      iex> "HTTP/1.1 204 No Content\\r\\n!!!BAD_HEADER\\r\\n\\r\\n"
      ...> |> Raxx.HTTP1.parse_response()
      {:error, {:invalid_line, "!!!BAD_HEADER\\r\\n"}}

      iex> "HTTP/1.1 204 No Content\\r\\nconnection: close\\r\\nfoo: bar\\r\\n\\r\\n"
      ...> |> Raxx.HTTP1.parse_response()
      {:ok, {%Raxx.Response{
        status: 204,
        headers: [{"foo", "bar"}],
        body: false
      }, :close, {:complete, ""}, ""}}

      iex> "HTTP/1.1 204 No Content\\r\\nconnection: keep-alive\\r\\nfoo: bar\\r\\n\\r\\n"
      ...> |> Raxx.HTTP1.parse_response()
      {:ok, {%Raxx.Response{
        status: 204,
        headers: [{"foo", "bar"}],
        body: false
      }, :keepalive, {:complete, ""}, ""}}
  """
  def parse_response(buffer) do
    case :erlang.decode_packet(:http_bin, buffer, []) do
      {:ok, {:http_response, {1, 1}, status, _reason_phrase}, rest} ->
        case parse_headers(rest) do
          {:ok, headers, rest2} ->
            {headers, body_present, body_read_state} = decode_payload(headers)

            {connection_status, headers} = decode_connection_status(headers)

            {:ok,
             {%Raxx.Response{status: status, headers: headers, body: body_present},
              connection_status, body_read_state, rest2}}

          {:error, reason} ->
            {:error, reason}
