ladybird/Userland/Services/WebServer/Client.h
Sam Atkins cce5e3158f WebServer: Handle incomplete HTTP requests
Mostly by copying the code in LibWeb/WebDriver/Client.cpp
2023-03-27 20:29:51 +01:00

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/Object.h>
#include <LibCore/Socket.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::BufferedTCPSocket>, Core::Object* 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;
};
}