HttpResponse.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/HashMap.h>
  9. #include <AK/String.h>
  10. #include <LibCore/NetworkResponse.h>
  11. namespace HTTP {
  12. class HttpResponse : public Core::NetworkResponse {
  13. public:
  14. virtual ~HttpResponse() override = default;
  15. static NonnullRefPtr<HttpResponse> create(int code, HashMap<String, String, CaseInsensitiveStringTraits>&& headers, size_t downloaded_size)
  16. {
  17. return adopt_ref(*new HttpResponse(code, move(headers), downloaded_size));
  18. }
  19. int code() const { return m_code; }
  20. size_t downloaded_size() const { return m_downloaded_size; }
  21. StringView reason_phrase() const { return reason_phrase_for_code(m_code); }
  22. HashMap<String, String, CaseInsensitiveStringTraits> const& headers() const { return m_headers; }
  23. static StringView reason_phrase_for_code(int code);
  24. private:
  25. HttpResponse(int code, HashMap<String, String, CaseInsensitiveStringTraits>&&, size_t size);
  26. int m_code { 0 };
  27. HashMap<String, String, CaseInsensitiveStringTraits> m_headers;
  28. size_t m_downloaded_size { 0 };
  29. };
  30. }