This repository provides the HTTP status codes and reason phrases in different variants for C/C++.
Simply take the variant that fits your needs and copy/use/modify it.
The status codes cover all codes registered with the IANA. Initially, the data was taken from for-GET/know-your-http-well.
| Variant | Name Scoping | Status Codes Type | Reason Phrases Type | 
|---|---|---|---|
| C | Prefix HttpStatus_ | enum HttpStatus_Code | const char* | 
| C++ | Namespace HttpStatus | enum Code | std::string | 
| C++11 | Namespace HttpStatus | enum class Code | std::string | 
| Qt | Namespace HttpStatus | enum CodeWhen using Qt 5.8 or later: registered in meta type system using Q_ENUM_NS() | QString | 
| Qt C++11 | Namespace HttpStatus | enum class CodeWhen using Qt 5.8 or later: registered in meta type system using Q_ENUM_NS() | QString | 
Note regarding Qt variant: Oldest tested Qt version was Qt 5.2.0 with MinGW 4.8. However, should be working with any Qt 5.x version. Might also be working with Qt 4 versions but this has not been tested.
#include "MyHttpReplyClass.h"
#include "HttpStatusCodes_C++.h"
#include <iostream>
void printReplyStatus( MyHttpReplyClass reply )
{
	if ( reply.status == HttpStatus::OK )
		std::cout << "Success!";
	else
		std::cerr << reply.status << " " << HttpStatus::reasonPhrase( reply.status );
}Note: The header files contain more detailed Doxygen documentation for all types and functions.
For the complete list of defined enums, see one of the header files.
Note: The maximum supported value for the enums is
1023. Trying to convert bigger values to the enum types might be undefined behavior.
enum HttpStatus_Code
{
	HttpStatus_Invalid  = -1,
	HttpStatus_OK       = 200,
	HttpStatus_NotFound = 404
	// ...
};namespace HttpStatus {
enum class Code
{
	Invalid  = -1,
	OK       = 200,
	NotFound = 404
	// ...
};
}namespace HttpStatus {
enum Code
{
	Invalid  = -1,
	OK       = 200,
	NotFound = 404
	// ...
};
}char HttpStatus_isInformational( int code );
char HttpStatus_isSuccessful( int code );
char HttpStatus_isRedirection( int code );
char HttpStatus_isClientError( int code );
char HttpStatus_isServerError( int code );Return 1 if the given code belongs to the corresponding class of status codes (see RFC7231).
Return 0 otherwise.
char HttpStatus_isError( int code);Returns 1 if the given code is either a client error, a server error or any non-standard error code.
Non-standard error codes are status codes with a value of 600 or higher.
Returns 0 otherwise.
bool HttpStatus::isInformational( int code );
bool HttpStatus::isSuccessful( int code );
bool HttpStatus::isRedirection( int code );
bool HttpStatus::isClientError( int code );
bool HttpStatus::isServerError( int code );
bool HttpStatus::isInformational( Code code ); // C++11 variants only
bool HttpStatus::isSuccessful( Code code );    // C++11 variants only
bool HttpStatus::isRedirection( Code code );   // C++11 variants only
bool HttpStatus::isClientError( Code code );   // C++11 variants only
bool HttpStatus::isServerError( Code code );   // C++11 variants onlyReturn true if the given code belongs to the corresponding class of status codes (see RFC7231).
Return false otherwise.
bool HttpStatus::isError( int code );
bool HttpStatus::isError( Code code ); // C++11 variants onlyReturns true if the given code is either a client error, a server error or any non-standard error code.
Non-standard error codes are status codes with a value of 600 or higher.
Returns false otherwise.
const char* HttpStatus_reasonPhrase( int code );Returns the HTTP reason phrase string corresponding to the given code.
std::string HttpStatus::reasonPhrase( int code );
std::string HttpStatus::reasonPhrase( Code code ); // C++11 variants onlyReturns the HTTP reason phrase string corresponding to the given code.
QString HttpStatus::reasonPhrase( int code );
QString HttpStatus::reasonPhrase( Code code ); // C++11 variant onlyReturns the HTTP reason phrase string corresponding to the given code.
int HttpStatus::toInt( HttpStatus::Code code );Returns the integer value corresponding to a given a code.
This is a convenience function as replacement for a static_cast<int>().
Code HttpStatus::networkErrorToStatusCode( QNetworkReply::NetworkError error );Returns the HTTP status code corresponding to the given error if there is one.
Otherwise, Code::Invalid (-1) is returned.
QNetworkReply::NetworkError HttpStatus::statusCodeToNetworkError( int code );
QNetworkReply::NetworkError HttpStatus::statusCodeToNetworkError( Code code ); // C++11 variant onlyReturns the QNetworkReply::NetworkError corresponding to the given code if there is one.
For codes where there is no exact match, the best matching "catch all" code (QNetworkReply::NoError,
QNetworkReply::UnknownContentError, QNetworkReply::UnknownServerError or QNetworkReply::ProtocolFailure)
is returned.
