LeftHookRoll
An HTTP/1.0 compliant web server, as specified by RFC1945
Loading...
Searching...
No Matches
AllowedMethods.cpp
Go to the documentation of this file.
1#include "../includes/AllowedMethods.hpp"
2
4
5AllowedMethods::AllowedMethods(const AllowedMethods& other) : _bitmap(other._bitmap) {}
6
8{
9 if (this != &other)
10 _bitmap = other._bitmap;
11 return *this;
12}
13
15
16// --- Bitwise Operations ---
17
19{
20 _bitmap |= method;
21}
22
24{
25 _bitmap &= ~method;
26}
27
29{
30 return (_bitmap & method) != 0;
31}
32
34{
35 _bitmap = 0;
36}
37
39{
40 return _bitmap;
41}
42
43HTTPMethod AllowedMethods::stringToMethod(const std::string& methodStr)
44{
45 if (methodStr == "GET")
46 return GET;
47 else if (methodStr == "POST")
48 return POST;
49 else if (methodStr == "DELETE")
50 return DELETE;
51 else
52 return UNKNOWN_METHOD;
53}
54
56{
57 if (method == GET)
58 return "GET";
59 if (method == POST)
60 return "POST";
61 if (method == DELETE)
62 return "DELETE";
63 return "UNKNOWN";
64}
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)