| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2024 Muhammad Nawaz | ||
| 3 | * Licensed under the MIT License. See LICENSE file for more information. | ||
| 4 | */ | ||
| 5 | // [ END OF LICENSE c6bd0f49d040fca8d8a9cb05868e66aa63f0e2e0 ] | ||
| 6 | |||
| 7 | #include "validators/method_validator.hpp" | ||
| 8 | |||
| 9 | 9 | MethodValidator::MethodValidator() | |
| 10 | 9 | : BaseValidator(ValidationError::INVALID_METHOD) | |
| 11 | { | ||
| 12 | 9 | } | |
| 13 | |||
| 14 | 91 | ValidationError MethodValidator::Validate(const std::string& method, std::string& err_msg) | |
| 15 | { | ||
| 16 |
3/4✓ Branch 2 taken 91 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 81 times.
|
91 | if (kValidMethods.find(method) == kValidMethods.end()) { |
| 17 |
4/8✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 10 times.
✗ Branch 12 not taken.
|
10 | err_msg += err_header_ + R"("description": "Invalid HTTP method ')" + method + "'" + R"("}})"; |
| 18 | 10 | return ValidationError::INVALID_METHOD; | |
| 19 | } | ||
| 20 | 81 | return ValidationError::NONE; | |
| 21 | } | ||
| 22 | |||
| 23 | const std::unordered_set<std::string> MethodValidator::kValidMethods = {"GET", "POST", "PUT", "DELETE", | ||
| 24 | "HEAD", "OPTIONS", "PATCH", "CONNECT", | ||
| 25 | "TRACE", "get", "post", "put", | ||
| 26 | "delete", "head", "options", "patch", | ||
| 27 | "connect", "trace"}; | ||
| 28 |