one more parser
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*********************************/
|
||||
/* */
|
||||
/* o.riabenkyi@gmail.com */
|
||||
/* */
|
||||
/*********************************/
|
||||
|
||||
#ifndef REQUEST_HPP
|
||||
#define REQUEST_HPP
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace webserv {
|
||||
|
||||
enum class Method { Get, Post, Delete };
|
||||
|
||||
const char* toString(Method method) noexcept;
|
||||
|
||||
bool headerNameEquals(std::string_view a, std::string_view b) noexcept;
|
||||
|
||||
enum class HttpVersion { Http10, Http11 };
|
||||
|
||||
struct Request {
|
||||
Method method;
|
||||
std::string target;
|
||||
HttpVersion version;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> headers;
|
||||
std::vector<char> body;
|
||||
|
||||
std::optional<std::string_view> header(std::string_view name) const noexcept;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*********************************/
|
||||
/* */
|
||||
/* o.riabenkyi@gmail.com */
|
||||
/* */
|
||||
/*********************************/
|
||||
|
||||
#ifndef REQUESTPARSER_HPP
|
||||
#define REQUESTPARSER_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
|
||||
#include "Result.hpp"
|
||||
#include "http/Request.hpp"
|
||||
|
||||
namespace webserv {
|
||||
|
||||
struct ParsedRequest {
|
||||
Request request;
|
||||
std::size_t consumed;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::optional<Result<ParsedRequest>> parseRequest(
|
||||
std::span<const char> data, std::size_t limit);
|
||||
|
||||
} // namespace webserv
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user