/* * Copyright (c) 2020, Andreas Kling * Copyright (c) 2022, Thomas Keppler * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace WebServer { class Client final : public Core::Object { C_OBJECT(Client); public: void start(); private: Client(NonnullOwnPtr, Core::Object* parent); using WrappedError = Variant; struct ContentInfo { String type; size_t length {}; }; ErrorOr on_ready_to_read(); ErrorOr handle_request(HTTP::HttpRequest const&); ErrorOr send_response(Stream&, HTTP::HttpRequest const&, ContentInfo); ErrorOr send_redirect(StringView redirect, HTTP::HttpRequest const&); ErrorOr send_error_response(unsigned code, HTTP::HttpRequest const&, Vector const& headers = {}); void die(); void log_response(unsigned code, HTTP::HttpRequest const&); ErrorOr handle_directory_listing(String const& requested_path, String const& real_path, HTTP::HttpRequest const&); bool verify_credentials(Vector const&); NonnullOwnPtr m_socket; StringBuilder m_remaining_request; }; }