     case state.requests[ref] do
       %Buffer{} = buffer ->
         HTTPoison.stream_next(%AsyncResponse{id: ref})
-        {:noreply, %{state | requests: %{state.requests | ref => %{buffer | status_code: code}}}}
-
+        new_requests = %{state.requests | ref => %{buffer | status_code: code}}
+        {:noreply, %{state | requests: new_requests}}
       nil ->
         {:noreply, state}
     end

          end)

        if redir do
          do_normal_request({method, redir, body, headers, opts, from}, file, state)
        else
          GenServer.reply(from, {:error, :no_server_for_redirect})
          {:noreply, state}
        end

      {:ok, %HTTPoison.Response{body: body, headers: headers, status_code: code}} ->
        GenServer.reply(from, {:ok, %Response{body: body, headers: headers, status_code: code}})
        {:noreply, state}

      {:ok, %AsyncResponse{id: ref}} ->


  defp do_api_request({method, url, body, headers, opts, from}, state) do
    alias Farmbot.System.ConfigStorage
    import ConfigStorage, only: [get_config_value: 3]
    token = get_config_value(:string, "authorization", "token")
    url = get_config_value(:string, "authorization", "server") <> url

    headers =
      headers
