
The current ProtocolServer was really only used for requests, and with the recent introduction of the WebSocket service, long-lasting connections with another server are not part of it. To better reflect this, this commit renames it to RequestServer. This commit also changes the existing 'protocol' portal to 'request', the existing 'protocol' user and group to 'request', and most mentions of the 'download' aspect of the request to 'request' when relevant, to make everything consistent across the system. Note that LibProtocol still exists as-is, but the more generic Client class and the more specific Download class have both been renamed to a more accurate RequestClient and Request to match the new names. This commit only change names, not behaviors.
54 lines
1.9 KiB
C++
54 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Function.h>
|
|
#include <AK/URL.h>
|
|
#include <LibCore/Object.h>
|
|
#include <LibWeb/Loader/Resource.h>
|
|
|
|
namespace Protocol {
|
|
class RequestClient;
|
|
}
|
|
|
|
namespace Web {
|
|
|
|
constexpr auto default_user_agent = "Mozilla/4.0 (SerenityOS; x86) LibWeb+LibJS (Not KHTML, nor Gecko) LibWeb";
|
|
|
|
class ResourceLoader : public Core::Object {
|
|
C_OBJECT(ResourceLoader)
|
|
public:
|
|
static ResourceLoader& the();
|
|
|
|
RefPtr<Resource> load_resource(Resource::Type, const LoadRequest&);
|
|
|
|
void load(const LoadRequest&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
|
void load(const URL&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
|
void load_sync(const LoadRequest&, Function<void(ReadonlyBytes, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> success_callback, Function<void(const String&, Optional<u32> status_code)> error_callback = nullptr);
|
|
|
|
Function<void()> on_load_counter_change;
|
|
|
|
int pending_loads() const { return m_pending_loads; }
|
|
|
|
Protocol::RequestClient& protocol_client() { return *m_protocol_client; }
|
|
|
|
const String& user_agent() const { return m_user_agent; }
|
|
void set_user_agent(const String& user_agent) { m_user_agent = user_agent; }
|
|
|
|
void clear_cache();
|
|
|
|
private:
|
|
ResourceLoader();
|
|
static bool is_port_blocked(int port);
|
|
|
|
int m_pending_loads { 0 };
|
|
|
|
RefPtr<Protocol::RequestClient> m_protocol_client;
|
|
String m_user_agent;
|
|
};
|
|
|
|
}
|