magpie
Loading...
Searching...
No Matches
magpie::StatusCode Struct Reference

#include <StatusCode.hpp>

Public Member Functions

constexpr StatusCode (unsigned short statusCode, std::string_view statusLine)
 StatusCode (StatusCode &)=delete
 StatusCode (StatusCode &&)=delete
 operator int () const
 operator short () const
bool operator== (const StatusCode &other) const
bool operator== (unsigned short code) const
bool operator== (long int code) const

Public Attributes

unsigned short statusCode
std::string_view statusLine

Detailed Description

Contains data for a status code.

Status codes are singletons, and cannot be generated on the fly. If you need additional status codes, create globals for them, and then use them. Creating them within a function is either a memory leak (new) or a segfault (returning a pointer to a temporary object).

This class has conversion semantics to int and strings. Magpie's built-in status objects can therefore be used to compare status codes of other libraries, provided the status code is stored as an int, or a string only containing the code number. For example, with libcpr, this code is perfectly valid:

cpr::Get(cpr::Url{ ... }).status_code == magpie::Status::OK

libcpr has no relation to this library (other than this library using it in tests), but because status_code is a number, the conversions makes it easier to use the same status codes with other unrelated libraries for standardisation. Probably only useful if you're writing tests for a magpie server, but ✨ the more you know ✨

Constructor & Destructor Documentation

◆ StatusCode()

magpie::StatusCode::StatusCode ( unsigned short statusCode,
std::string_view statusLine )
inlineconstexpr
Parameters
statusCodeThe HTTP status code
statusLineThe HTTP status line. Only matters for HTTP/1.1, as HTTP/2 and newer do not use this field.

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