2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-03-03 11:35:10 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-04-07 14:36:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
#include <AK/ByteString.h>
|
2019-04-07 14:36:10 +02:00
|
|
|
#include <AK/HashMap.h>
|
2020-02-06 15:04:03 +01:00
|
|
|
#include <LibCore/NetworkResponse.h>
|
2019-04-07 14:36:10 +02:00
|
|
|
|
2020-04-21 01:55:25 +04:30
|
|
|
namespace HTTP {
|
2020-02-02 12:34:39 +01:00
|
|
|
|
2020-04-21 01:55:25 +04:30
|
|
|
class HttpResponse : public Core::NetworkResponse {
|
2019-04-07 14:36:10 +02:00
|
|
|
public:
|
2022-03-03 11:35:10 -07:00
|
|
|
virtual ~HttpResponse() override = default;
|
2023-12-16 17:49:34 +03:30
|
|
|
static NonnullRefPtr<HttpResponse> create(int code, HashMap<ByteString, ByteString, CaseInsensitiveStringTraits>&& headers, size_t downloaded_size)
|
2019-04-07 14:36:10 +02:00
|
|
|
{
|
2022-02-02 19:21:55 +03:30
|
|
|
return adopt_ref(*new HttpResponse(code, move(headers), downloaded_size));
|
2019-04-07 14:36:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int code() const { return m_code; }
|
2022-02-02 19:21:55 +03:30
|
|
|
size_t downloaded_size() const { return m_downloaded_size; }
|
2021-06-05 14:28:11 +02:00
|
|
|
StringView reason_phrase() const { return reason_phrase_for_code(m_code); }
|
2023-12-16 17:49:34 +03:30
|
|
|
HashMap<ByteString, ByteString, CaseInsensitiveStringTraits> const& headers() const { return m_headers; }
|
2021-06-05 14:28:11 +02:00
|
|
|
|
|
|
|
static StringView reason_phrase_for_code(int code);
|
2019-04-07 14:36:10 +02:00
|
|
|
|
|
|
|
private:
|
2023-12-16 17:49:34 +03:30
|
|
|
HttpResponse(int code, HashMap<ByteString, ByteString, CaseInsensitiveStringTraits>&&, size_t size);
|
2019-04-07 14:36:10 +02:00
|
|
|
|
|
|
|
int m_code { 0 };
|
2023-12-16 17:49:34 +03:30
|
|
|
HashMap<ByteString, ByteString, CaseInsensitiveStringTraits> m_headers;
|
2022-02-02 19:21:55 +03:30
|
|
|
size_t m_downloaded_size { 0 };
|
2019-04-07 14:36:10 +02:00
|
|
|
};
|
2020-02-02 12:34:39 +01:00
|
|
|
|
|
|
|
}
|