ladybird/Userland/Services/WebServer/Client.h
implicitfield 896f213c6f LibFileSystem+Userland: Rename size() to size_from_stat()
This reflects what the functions does more accurately, and allows for
adding functions to get sizes through other methods.

This also corrects the return type of said function, as size_t may only
hold sizes up to 4GB on 32-bit platforms.
2024-02-24 15:54:52 -07:00

49 lines
1.4 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Thomas Keppler <serenity@tkeppler.de>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <LibCore/EventReceiver.h>
#include <LibCore/Socket.h>
#include <LibHTTP/Forward.h>
#include <LibHTTP/HttpRequest.h>
namespace WebServer {
class Client final : public Core::EventReceiver {
C_OBJECT(Client);
public:
void start();
private:
Client(NonnullOwnPtr<Core::BufferedTCPSocket>, Core::EventReceiver* parent);
using WrappedError = Variant<AK::Error, HTTP::HttpRequest::ParseError>;
struct ContentInfo {
String type;
u64 length {};
};
ErrorOr<void, WrappedError> on_ready_to_read();
ErrorOr<bool> handle_request(HTTP::HttpRequest const&);
ErrorOr<void> send_response(Stream&, HTTP::HttpRequest const&, ContentInfo);
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::BufferedTCPSocket> m_socket;
StringBuilder m_remaining_request;
};
}