mirror of
https://review.haiku-os.org/haiku
synced 2025-02-01 03:06:08 +01:00
ec865cb87e
This class provides defaults and performs basic validation for HTTP Methods as defined by the standard. They will be used in conjunction with a future BHttpRequest class. Change-Id: If69a7ec186d9d1165e8efe5ab5df50d5a089208d
70 lines
1.3 KiB
C++
70 lines
1.3 KiB
C++
/*
|
|
* Copyright 2022 Haiku Inc. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
|
|
#ifndef _B_HTTP_REQUEST_H_
|
|
#define _B_HTTP_REQUEST_H_
|
|
|
|
#include <string_view>
|
|
#include <variant>
|
|
|
|
#include <ErrorsExt.h>
|
|
#include <String.h>
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
namespace Network {
|
|
|
|
|
|
class BHttpMethod {
|
|
public:
|
|
// Constants for default methods in RFC 7230 section 4.2
|
|
enum Verb {
|
|
Get,
|
|
Head,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Connect,
|
|
Options,
|
|
Trace
|
|
};
|
|
|
|
// Error type when constructing with a custom method
|
|
class InvalidMethod : public BError {
|
|
public:
|
|
InvalidMethod(const char* origin, BString input);
|
|
|
|
virtual const char* Message() const noexcept override;
|
|
virtual BString DebugMessage() const override;
|
|
|
|
BString input;
|
|
};
|
|
|
|
// Constructors & Destructor
|
|
BHttpMethod(Verb verb) noexcept;
|
|
BHttpMethod(const std::string_view& method);
|
|
BHttpMethod(const BHttpMethod& other);
|
|
BHttpMethod(BHttpMethod&& other) noexcept;
|
|
~BHttpMethod();
|
|
|
|
// Assignment operators
|
|
BHttpMethod& operator=(const BHttpMethod& other);
|
|
BHttpMethod& operator=(BHttpMethod&& other) noexcept;
|
|
|
|
// Get the method as a string
|
|
const std::string_view Method() const noexcept;
|
|
|
|
private:
|
|
std::variant<Verb, BString> fMethod;
|
|
};
|
|
|
|
|
|
} // namespace Network
|
|
|
|
} // namespace BPrivate
|
|
|
|
#endif // B_HTTP_REQUEST
|