mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 16:55:07 +00:00

As per previous discussion, it was decided that the Stream classes should be constructed on the heap. While I don't personally agree with this change, it does have the benefit of avoiding Function object reconstructions due to the lambda passed to Notifier pointing to a stale object reference. This also has the benefit of not having to "box" objects for virtual usage, as the objects come pre-boxed. However, it means that we now hit the heap everytime we construct a TCPSocket for instance, which might not be desirable.
37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibCore/Object.h>
|
|
#include <LibCore/Stream.h>
|
|
#include <LibHTTP/Forward.h>
|
|
#include <LibHTTP/HttpRequest.h>
|
|
|
|
namespace WebServer {
|
|
|
|
class Client final : public Core::Object {
|
|
C_OBJECT(Client);
|
|
|
|
public:
|
|
void start();
|
|
|
|
private:
|
|
Client(NonnullOwnPtr<Core::Stream::BufferedTCPSocket>, Core::Object* parent);
|
|
|
|
ErrorOr<bool> handle_request(ReadonlyBytes);
|
|
ErrorOr<void> send_response(InputStream&, HTTP::HttpRequest const&, String const& content_type);
|
|
ErrorOr<void> send_redirect(StringView redirect, HTTP::HttpRequest const&);
|
|
ErrorOr<void> send_error_response(unsigned code, HTTP::HttpRequest const&, Vector<String> const& headers = {});
|
|
void die();
|
|
void log_response(unsigned code, HTTP::HttpRequest const&);
|
|
ErrorOr<void> handle_directory_listing(String const& requested_path, String const& real_path, HTTP::HttpRequest const&);
|
|
bool verify_credentials(Vector<HTTP::HttpRequest::Header> const&);
|
|
|
|
NonnullOwnPtr<Core::Stream::BufferedTCPSocket> m_socket;
|
|
};
|
|
|
|
}
|