RESTinio
Public Member Functions | Static Public Attributes | Private Attributes | Friends | List of all members
restinio::http_method_id_t Class Reference

A type for representation of HTTP method ID. More...

#include <http_headers.hpp>

Public Member Functions

constexpr http_method_id_t () noexcept
 
constexpr http_method_id_t (int value, const char *name) noexcept
 
constexpr http_method_id_t (const http_method_id_t &) noexcept=default
 
constexpr http_method_id_toperator= (const http_method_id_t &) noexcept=default
 
constexpr http_method_id_t (http_method_id_t &&) noexcept=default
 
constexpr http_method_id_toperator= (http_method_id_t &&) noexcept=default
 
constexpr auto raw_id () const noexcept
 
constexpr const char * c_str () const noexcept
 

Static Public Attributes

static constexpr const int unknown_method = -1
 

Private Attributes

int m_value
 
const char * m_name
 

Friends

constexpr bool operator== (const http_method_id_t &a, const http_method_id_t &b) noexcept
 
constexpr bool operator!= (const http_method_id_t &a, const http_method_id_t &b) noexcept
 
constexpr bool operator< (const http_method_id_t &a, const http_method_id_t &b) noexcept
 

Detailed Description

A type for representation of HTTP method ID.

RESTinio uses http_parser for working with HTTP-protocol. HTTP-methods in http_parser are identified by ints like HTTP_GET, HTTP_POST and so on.

Usage of plain int is error prone. So since v.0.5.0 RESTinio contain type http_method_id_t as type for ID of HTTP method.

An instance of http_method_id_t contains two values:

There is an important requirement for user-defined HTTP method IDs: a pointer to string representation of HTTP method ID must outlive the instance of http_method_id_t. It means that is safe to use string literals or static strings, for example:

constexpr const restinio::http_method_id_t my_http_method(255, "MY-METHOD");
Note
Instances of http_method_id_t can't be used in switch() operator. For example, you can't write that way:
const int method_id = ...;
switch(method_id) {
case restinio::http_method_get(): ...; break;
case restinio::http_method_post(): ...; break;
case restinio::http_method_delete(): ...; break;
}
In that case raw_id() method can be used:
const int method_id = ...;
switch(method_id) {
case restinio::http_method_get().raw_id(): ...; break;
case restinio::http_method_post().raw_id(): ...; break;
case restinio::http_method_delete().raw_id(): ...; break;
}
Since
v.0.5.0

Definition at line 1537 of file http_headers.hpp.

Constructor & Destructor Documentation

◆ http_method_id_t() [1/4]

constexpr restinio::http_method_id_t::http_method_id_t ( )
inlinenoexcept

Definition at line 1545 of file http_headers.hpp.

◆ http_method_id_t() [2/4]

constexpr restinio::http_method_id_t::http_method_id_t ( int  value,
const char *  name 
)
inlinenoexcept

Definition at line 1549 of file http_headers.hpp.

◆ http_method_id_t() [3/4]

constexpr restinio::http_method_id_t::http_method_id_t ( const http_method_id_t )
defaultnoexcept

◆ http_method_id_t() [4/4]

constexpr restinio::http_method_id_t::http_method_id_t ( http_method_id_t &&  )
defaultnoexcept

Member Function Documentation

◆ c_str()

constexpr const char* restinio::http_method_id_t::c_str ( ) const
inlinenoexcept

Definition at line 1568 of file http_headers.hpp.

◆ operator=() [1/2]

constexpr http_method_id_t& restinio::http_method_id_t::operator= ( const http_method_id_t )
defaultnoexcept

◆ operator=() [2/2]

constexpr http_method_id_t& restinio::http_method_id_t::operator= ( http_method_id_t &&  )
defaultnoexcept

◆ raw_id()

constexpr auto restinio::http_method_id_t::raw_id ( ) const
inlinenoexcept

Definition at line 1565 of file http_headers.hpp.

Friends And Related Function Documentation

◆ operator!=

constexpr bool operator!= ( const http_method_id_t a,
const http_method_id_t b 
)
friend

Definition at line 1576 of file http_headers.hpp.

◆ operator<

constexpr bool operator< ( const http_method_id_t a,
const http_method_id_t b 
)
friend

Definition at line 1581 of file http_headers.hpp.

◆ operator==

constexpr bool operator== ( const http_method_id_t a,
const http_method_id_t b 
)
friend

Definition at line 1571 of file http_headers.hpp.

Member Data Documentation

◆ m_name

const char* restinio::http_method_id_t::m_name
private

Definition at line 1540 of file http_headers.hpp.

◆ m_value

int restinio::http_method_id_t::m_value
private

Definition at line 1539 of file http_headers.hpp.

◆ unknown_method

constexpr const int restinio::http_method_id_t::unknown_method = -1
static

Definition at line 1543 of file http_headers.hpp.


The documentation for this class was generated from the following file: