Classes | Public Types | Public Member Functions | List of all members
BPrivate::Network::BHttpMethod Class Reference

Represent a HTTP method. More...

Classes

class  InvalidMethod
 Error that represents when a custom method does not conform to the HTTP standard. More...
 

Public Types

enum  Verb {
  Get,
  Head,
  Post,
  Put,
  Delete,
  Connect,
  Options,
  Trace
}
 A list of standard HTTP methods. More...
 

Public Member Functions

 BHttpMethod (BHttpMethod &&other) noexcept
 Move constructor. More...
 
 BHttpMethod (const BHttpMethod &other)
 Copy constructor. More...
 
 BHttpMethod (const std::string_view &method)
 Construct a custom method. More...
 
 BHttpMethod (Verb verb) noexcept
 Construct a standard method. More...
 
 ~BHttpMethod ()
 Destructor. More...
 
const std::string_view Method () const noexcept
 Get a string representation of the method. More...
 
bool operator!= (const Verb &other) const noexcept
 Comparison operator. More...
 
BHttpMethodoperator= (BHttpMethod &&other) noexcept
 Move assignment. Moves the data from the other to this object. The other object will be set to BHttpMethod::Get. More...
 
BHttpMethodoperator= (const BHttpMethod &other)
 Copy assignment. More...
 
bool operator== (const Verb &other) const noexcept
 Comparison operator. More...
 

Detailed Description

Represent a HTTP method.

The HTTP standard specifies that HTTP requests have a method. Common methods are GET and HEAD methods. Standardized and common methods are in the form of verbs and are in capitalized letters from the ASCII token set, though any valid token can be used.

It is most likely that you will not use the methods of this class directly, instead you will use the implicit constructors while interacting with the BHttpRequest class.

auto url = BUrl("https://www.haiku-os.org/");
// implicitly construct a standard get request
auto standard = BHttpRequest(url, BHttpMethod::Get);
// implicitly construct a nonstandard patch request
auto custom = BHttpRequest(url, "PATCH"sv);
Note
When you are using the standard list of verbs, there will never be an exception when creating objects of this type. When you create a custom method, exceptions may be raised when the system runs out of memory, or when your custom method contains invalid characters. In almost all cases, you can probably safely assume you will not run into these exceptions, except for cases where you use user input to create methods or you are very defensive about memory management.
Since
Haiku R1

Constructor & Destructor Documentation

◆ BHttpMethod() [1/4]

BPrivate::Network::BHttpMethod::BHttpMethod ( Verb  verb)
noexcept

Construct a standard method.

Parameters
verbThe chosen method.
Since
Haiku R1

◆ BHttpMethod() [2/4]

BPrivate::Network::BHttpMethod::BHttpMethod ( const std::string_view &  method)

Construct a custom method.

Parameters
methodThe verb for the method.
Exceptions
std::bad_allocIn case it is not possible to allocate memory for the custom string.
BHttpMethod::InvalidMethodIn case the method is empty or contains invalid characters.
Since
Haiku R1

◆ BHttpMethod() [3/4]

BPrivate::Network::BHttpMethod::BHttpMethod ( const BHttpMethod other)

Copy constructor.

Copy data from an other object.

Exceptions
std::bad_allocWhen the other object contains a custom verb, this exception will be raised if it is impossible to allocate memory.
Since
Haiku R1

◆ BHttpMethod() [4/4]

BPrivate::Network::BHttpMethod::BHttpMethod ( BHttpMethod &&  other)
noexcept

Move constructor.

Moves the data from the other to this object. The other object will be set to BHttpMethod::Get.

Since
Haiku R1

◆ ~BHttpMethod()

BPrivate::Network::BHttpMethod::~BHttpMethod ( )

Destructor.

Since
Haiku R1

Member Function Documentation

◆ Method()

const std::string_view BPrivate::Network::BHttpMethod::Method ( ) const
noexcept

Get a string representation of the method.

Returns
A std::string_view that is a string representation of the standard or custom method in this object. The lifetime of the string view is bound to the lifetime of this method.
Since
Haiku R1

◆ operator!=()

bool BPrivate::Network::BHttpMethod::operator!= ( const Verb other) const
noexcept

Comparison operator.

Parameters
otherThe verb to compare to.
Return values
trueThis method is different from other.
falseThis method is equal to other.
Since
Haiku R1

◆ operator=() [1/2]

BHttpMethod & BPrivate::Network::BHttpMethod::operator= ( BHttpMethod &&  other)
noexcept

Move assignment. Moves the data from the other to this object. The other object will be set to BHttpMethod::Get.

Since
Haiku R1

◆ operator=() [2/2]

BHttpMethod & BPrivate::Network::BHttpMethod::operator= ( const BHttpMethod other)

Copy assignment.

Copy data from an other object.

Exceptions
std::bad_allocWhen the other object contains a custom verb, this exception will be raised if it is impossible to allocate memory.
Since
Haiku R1

◆ operator==()

bool BPrivate::Network::BHttpMethod::operator== ( const Verb other) const
noexcept

Comparison operator.

Parameters
otherThe verb to compare to.
Return values
trueThis method is equal to other.
falseThis method is different from other.
Since
Haiku R1
BUrl
Represents and manipulates an URL (Uniform Resource Locator).
Definition: Url.h:15
BPrivate::Network::BHttpMethod::Get
Represents the GET method.
Definition: HttpRequest.h:36