LeftHookRoll
An HTTP/1.0 compliant web server, as specified by RFC1945
Loading...
Searching...
No Matches
AllowedMethods.hpp
Go to the documentation of this file.
1/**
2 * @file AllowedMethods.hpp
3 * @author Yaman Al-Rifai(you@domain.com)
4 * @brief
5 * @version 0.1
6 * @date 2026-02-23
7 *
8 * @copyright Copyright (c) 2026
9 *
10 */
11#pragma once
12#include <string>
13/**
14 * @enum HTTPMethod
15 * @brief Represents the HTTP methods supported by the server as a bitmask.
16 */
18{
19 UNKNOWN_METHOD = 0, //000
20 GET = 1 << 0, //001
21 POST = 1 << 1, //010
22 DELETE = 1 << 2 //100
23};
24
25/**
26 * @class AllowedMethods
27 * @brief A lightweight wrapper for a short bitmap to handle HTTP method validations securely.
28 */
30{
31 public:
32 // Canonical Form
34 AllowedMethods(const AllowedMethods& other);
37
38 // Bitwise Operations
39
40 /**
41 * @brief Adds an HTTP method to the allowed bitmap using bitwise OR.
42 */
43 void addMethod(HTTPMethod method);
44
45 /**
46 * @brief Removes an HTTP method from the allowed bitmap using bitwise AND NOT.
47 */
48 void removeMethod(HTTPMethod method);
49
50 /**
51 * @brief Checks if a specific HTTP method is permitted using bitwise AND.
52 */
53 bool isAllowed(HTTPMethod method) const;
54
55 /**
56 * @brief Clears all methods (resets to 0 / UNKNOWN_METHOD).
57 */
58 void clear();
59
60 /**
61 * @brief Returns the raw bitmap.
62 */
63 short getBitmap() const;
64
65 /**
66 * @brief Converts a string representation of an HTTP method to its enum value.
67 */
68 static HTTPMethod stringToMethod(const std::string& methodStr);
69 static std::string methodToString(HTTPMethod method);
70 private:
71 short _bitmap;
72};
HTTPMethod
Represents the HTTP methods supported by the server as a bitmask.
@ GET
@ POST
@ UNKNOWN_METHOD
@ DELETE
A lightweight wrapper for a short bitmap to handle HTTP method validations securely.
short getBitmap() const
Returns the raw bitmap.
bool isAllowed(HTTPMethod method) const
Checks if a specific HTTP method is permitted using bitwise AND.
void clear()
Clears all methods (resets to 0 / UNKNOWN_METHOD).
static std::string methodToString(HTTPMethod method)
static HTTPMethod stringToMethod(const std::string &methodStr)
Converts a string representation of an HTTP method to its enum value.
void addMethod(HTTPMethod method)
Adds an HTTP method to the allowed bitmap using bitwise OR.
void removeMethod(HTTPMethod method)
Removes an HTTP method from the allowed bitmap using bitwise AND NOT.
AllowedMethods & operator=(const AllowedMethods &other)