mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
ddbe6bd7b4
This is a more precise description of what this class actually does.
48 lines
1.4 KiB
C++
48 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;
|
|
size_t 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;
|
|
};
|
|
|
|
}
|