Serenity Operating System
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
8#pragma once
9
10#include <AK/DeprecatedString.h>
11#include <AK/HashMap.h>
12#include <LibCore/NetworkResponse.h>
13
14namespace HTTP {
15
16class HttpResponse : public Core::NetworkResponse {
17public:
18 virtual ~HttpResponse() override = default;
19 static NonnullRefPtr<HttpResponse> create(int code, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits>&& headers, size_t downloaded_size)
20 {
21 return adopt_ref(*new HttpResponse(code, move(headers), downloaded_size));
22 }
23
24 int code() const { return m_code; }
25 size_t downloaded_size() const { return m_downloaded_size; }
26 StringView reason_phrase() const { return reason_phrase_for_code(m_code); }
27 HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& headers() const { return m_headers; }
28
29 static StringView reason_phrase_for_code(int code);
30
31private:
32 HttpResponse(int code, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits>&&, size_t size);
33
34 int m_code { 0 };
35 HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> m_headers;
36 size_t m_downloaded_size { 0 };
37};
38
39}