Add status code files to server
parent
2733153826
commit
4200b4a6d6
|
@ -0,0 +1,18 @@
|
|||
#include "status_codes.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
const char *get_message_from_status_code(int status_code) {
|
||||
if (status_code > 100 && status_code < 100 + NUM_100_STATUS_CODES) {
|
||||
return STATUS_CODES_100[status_code - 100];
|
||||
} else if (status_code > 200 && status_code < 200 + NUM_200_STATUS_CODES) {
|
||||
return STATUS_CODES_200[status_code - 200];
|
||||
} else if (status_code > 300 && status_code < 300 + NUM_300_STATUS_CODES) {
|
||||
return STATUS_CODES_300[status_code - 300];
|
||||
} else if (status_code > 400 && status_code < 400 + NUM_400_STATUS_CODES) {
|
||||
return STATUS_CODES_400[status_code - 400];
|
||||
} else if (status_code > 500 && status_code < 500 + NUM_500_STATUS_CODES) {
|
||||
return STATUS_CODES_500[status_code - 500];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef STATUS_CODES_H
|
||||
#define STATUS_CODES_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define NUM_100_STATUS_CODES 2
|
||||
#define NUM_200_STATUS_CODES 7
|
||||
#define NUM_300_STATUS_CODES 8
|
||||
#define NUM_400_STATUS_CODES 18
|
||||
#define NUM_500_STATUS_CODES 6
|
||||
|
||||
const char *STATUS_CODES_100[] = {
|
||||
"Continue",
|
||||
"Switching Protocols"
|
||||
};
|
||||
|
||||
const char *STATUS_CODES_200[] = {
|
||||
"OK",
|
||||
"Created",
|
||||
"Accepted",
|
||||
"Non-Authoritative Information",
|
||||
"No Content",
|
||||
"Reset Content",
|
||||
"Partial Content",
|
||||
};
|
||||
|
||||
const char *STATUS_CODES_300[] = {
|
||||
"Multiple Choices",
|
||||
"Moved Permanently",
|
||||
"Found",
|
||||
"See Other",
|
||||
"Not Modified",
|
||||
"Use Proxy",
|
||||
NULL, // There is no status code 306
|
||||
"Temporary Redirect",
|
||||
};
|
||||
|
||||
const char *STATUS_CODES_400[] = {
|
||||
"Bad Request",
|
||||
"Unauthorized",
|
||||
"Payment Required",
|
||||
"Forbidden",
|
||||
"Not Found",
|
||||
"Method Not Allowed",
|
||||
"Not Acceptable",
|
||||
"Proxy Authentication Required",
|
||||
"Request Time-out",
|
||||
"Conflict",
|
||||
"Gone",
|
||||
"Length Required",
|
||||
"Precondition Failed",
|
||||
"Request Entity Too Large",
|
||||
"Request-URI Too Large",
|
||||
"Unsupported Media Type",
|
||||
"Requested range not satisfiable",
|
||||
"Expectation Failed",
|
||||
};
|
||||
|
||||
const char *STATUS_CODES_500[] = {
|
||||
"Internal Server Error",
|
||||
"Not Implemented",
|
||||
"Bad Gateway",
|
||||
"Service Unavailable",
|
||||
"Gateway Time-out",
|
||||
"HTTP Version not supported"
|
||||
};
|
||||
|
||||
const char *get_message_from_status_code(int status_code);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue