71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "webserv/http/HttpHeaders.hpp"
|
|
|
|
#include <webserv/config/ServerConfig.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
class Client;
|
|
|
|
class HttpRequest
|
|
{
|
|
public:
|
|
enum class State : std::uint8_t
|
|
{
|
|
RequestLine,
|
|
Headers,
|
|
Body,
|
|
Chunked,
|
|
Complete,
|
|
ParseError
|
|
};
|
|
|
|
HttpRequest(const ServerConfig *serverConfig, const Client *client);
|
|
|
|
HttpRequest(const HttpRequest &other) = delete;
|
|
HttpRequest(HttpRequest &&other) noexcept = delete;
|
|
HttpRequest &operator=(const HttpRequest &other) = delete;
|
|
HttpRequest &operator=(HttpRequest &&other) noexcept = delete;
|
|
~HttpRequest();
|
|
|
|
[[nodiscard]] State getState() const;
|
|
[[nodiscard]] const HttpHeaders &getHeaders() const;
|
|
[[nodiscard]] const std::string &getBody() const;
|
|
|
|
[[nodiscard]] const std::string &getMethod() const { return method_; }
|
|
[[nodiscard]] const std::string &getTarget() const { return target_; }
|
|
[[nodiscard]] const std::string &getHttpVersion() const { return httpVersion_; }
|
|
|
|
void receiveData(const char *data, size_t length);
|
|
void reset();
|
|
|
|
private:
|
|
void parseBuffer();
|
|
[[nodiscard]] bool parseBufferforRequestLine();
|
|
[[nodiscard]] bool parseBufferforHeaders();
|
|
[[nodiscard]] bool parseHeaderLine();
|
|
[[nodiscard]] bool parseBufferforBody();
|
|
[[nodiscard]] bool parseBufferforChunkedBody();
|
|
|
|
void parseContentLength();
|
|
|
|
const ServerConfig *serverConfig_;
|
|
const Client *client_;
|
|
|
|
State state_ = State::RequestLine;
|
|
|
|
HttpHeaders headers_;
|
|
|
|
std::string buffer_;
|
|
std::string body_;
|
|
std::string method_;
|
|
std::string target_;
|
|
std::string httpVersion_;
|
|
// std::string requestLine_;
|
|
// std::string headers_;
|
|
// size_t contentLength_ = 0;
|
|
};
|