Skip to content

Commit

Permalink
Added additional non-official/standard HTTP status codes.
Browse files Browse the repository at this point in the history
This fixes #2634 by adding status code 0 seen in Caddy.
  • Loading branch information
allinurl committed Apr 9, 2024
1 parent b751f29 commit d7c7dac
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 12 deletions.
4 changes: 4 additions & 0 deletions resources/css/app.css
Expand Up @@ -402,6 +402,10 @@ div.wrap-panel > div {
background: #fce8e6;
color: #c5221f;
}
.wrap-panel table .span-hl.lgry {
background: #898989;
color: #ffffff;
}
.wrap-panel table .span-hl.lblu {
background: #cfe2ff;
color: #052c65;
Expand Down
2 changes: 1 addition & 1 deletion src/gstorage.c
Expand Up @@ -1321,7 +1321,7 @@ static int
gen_status_code_key (GKeyData *kdata, GLogItem *logitem) {
const char *status = NULL, *type = NULL;

if (!logitem->status)
if (logitem->status == -1)
return 1;

status = verify_status_code (logitem->status);
Expand Down
48 changes: 48 additions & 0 deletions src/labels.h
Expand Up @@ -398,6 +398,8 @@
N_("Table Columns")

/* Status Codes */
#define STATUS_CODE_0XX \
N_("0xx Unofficial Codes")
#define STATUS_CODE_1XX \
N_("1xx Informational")
#define STATUS_CODE_2XX \
Expand All @@ -409,6 +411,8 @@
#define STATUS_CODE_5XX \
N_("5xx Server Errors")

#define STATUS_CODE_0 \
N_("0 - Caddy: Unhandled - No configured routes")
#define STATUS_CODE_100 \
N_("100 - Continue: Server received the initial part of the request")
#define STATUS_CODE_101 \
Expand All @@ -431,6 +435,8 @@
N_("207 - Multi-Status: WebDAV; RFC 4918")
#define STATUS_CODE_208 \
N_("208 - Already Reported: WebDAV; RFC 5842")
#define STATUS_CODE_218 \
N_("218 - This is fine: Apache servers. A catch-all error condition")
#define STATUS_CODE_300 \
N_("300 - Multiple Choices: Multiple options for the resource")
#define STATUS_CODE_301 \
Expand Down Expand Up @@ -485,6 +491,10 @@
N_("417 - Expectation Failed")
#define STATUS_CODE_418 \
N_("418 - I'm a teapot")
#define STATUS_CODE_419 \
N_("419 - Page Expired: Laravel Framework when a CSRF Token is missing")
#define STATUS_CODE_420 \
N_("420 - Method Failure: Spring Framework when a method has failed")
#define STATUS_CODE_421 \
N_("421 - Misdirected Request")
#define STATUS_CODE_422 \
Expand All @@ -499,12 +509,26 @@
N_("428 - Precondition Required")
#define STATUS_CODE_429 \
N_("429 - Too Many Requests: The user has sent too many requests")
#define STATUS_CODE_430 \
N_("430 - Request Header Fields Too Large: Too many URLs are requested within a certain time frame")
#define STATUS_CODE_431 \
N_("431 - Request Header Fields Too Large")
#define STATUS_CODE_440 \
N_("440 - Login Time-out: The client's session has expired")
#define STATUS_CODE_449 \
N_("449 - Retry With: The server cannot honour the request")
#define STATUS_CODE_450 \
N_("450 - Blocked by Windows Parental Controls: The Microsoft extension code indicated")
#define STATUS_CODE_451 \
N_("451 - Unavailable For Legal Reasons")
#define STATUS_CODE_444 \
N_("444 - (Nginx) Connection closed without sending any headers")
#define STATUS_CODE_460 \
N_("460 - AWS Elastic Load Balancing: Client closed the connection ")
#define STATUS_CODE_463 \
N_("463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP addresses")
#define STATUS_CODE_464 \
N_("464 - AWS Elastic Load Balancing: Incompatible protocol versions")
#define STATUS_CODE_494 \
N_("494 - (Nginx) Request Header Too Large")
#define STATUS_CODE_495 \
Expand All @@ -513,6 +537,8 @@
N_("496 - (Nginx) Client didn't provide certificate")
#define STATUS_CODE_497 \
N_("497 - (Nginx) HTTP request sent to HTTPS port")
#define STATUS_CODE_498 \
N_("498 - Invalid Token: an expired or otherwise invalid token")
#define STATUS_CODE_499 \
N_("499 - (Nginx) Connection closed by client while processing request")
#define STATUS_CODE_500 \
Expand All @@ -527,6 +553,8 @@
N_("504 - Gateway Timeout: The upstream server failed to send request")
#define STATUS_CODE_505 \
N_("505 - HTTP Version Not Supported")
#define STATUS_CODE_509 \
N_("509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth")
#define STATUS_CODE_520 \
N_("520 - CloudFlare - Web server is returning an unknown error")
#define STATUS_CODE_521 \
Expand All @@ -537,5 +565,25 @@
N_("523 - CloudFlare - Origin is unreachable")
#define STATUS_CODE_524 \
N_("524 - CloudFlare - A timeout occurred")
#define STATUS_CODE_525 \
N_("525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS handshake")
#define STATUS_CODE_526 \
N_("526 - Invalid SSL Certificate: Cloudflare could not validate the SSL certificate")
#define STATUS_CODE_527 \
N_("527 - Railgun Error: An interrupted connection")
#define STATUS_CODE_529 \
N_("529 - Site is overloaded: A site can not process the request")
#define STATUS_CODE_530 \
N_("530 - Site is frozen: A site has been frozen due to inactivity")
#define STATUS_CODE_540 \
N_("540 - Temporarily Disabled: The requested endpoint has been temporarily disabled")
#define STATUS_CODE_561 \
N_("561 - Unauthorized: An error around authentication")
#define STATUS_CODE_598 \
N_("598 - Network read timeout error: some HTTP proxies to signal a network read timeout")
#define STATUS_CODE_599 \
N_("599 - Network Connect Timeout Error: An error used by some HTTP proxies")
#define STATUS_CODE_783 \
N_("783 - Unexpected Token: The request includes a JSON syntax error")

#endif // for #ifndef LABELS_H
1 change: 1 addition & 0 deletions src/output.c
Expand Up @@ -942,6 +942,7 @@ print_def_data (FILE *fp, GModule module, int sp) {
"\\\"^(3\\\\\\\\d{2}|3xx)(\\\\\\\\s.*)$\\\": \\\"<b class='span-hl lprp'>$1</b>$2\\\"," /* 3xx Success */
"\\\"^(4\\\\\\\\d{2}|4xx)(\\\\\\\\s.*)$\\\": \\\"<b class='span-hl lyel'>$1</b>$2\\\"," /* 4xx Success */
"\\\"^(5\\\\\\\\d{2}|5xx)(\\\\\\\\s.*)$\\\": \\\"<b class='span-hl lred'>$1</b>$2\\\"," /* 5xx Success */
"\\\"^(0\\\\\\\\d{2}|0xx)(\\\\\\\\s.*)$\\\": \\\"<b class='span-hl lgry'>$1</b>$2\\\"," /* 5xx Success */
"\\\"^(AS\\\\\\\\d+)\\\": \\\"<b>$1</b>\\\"," /* AS9823 Google */
"\\\"^(\\\\\\\\d+:)\\\": \\\"<b>$1</b>\\\"," /* 01234: Data */
"\\\"(\\\\\\\\d+)|(:\\\\\\\\d+)|(:\\\\\\\\d+:\\\\\\\\d+)\\\": \\\"$1<b>$2</b>\\\"," /* 12/May/2022:12:34 */
Expand Down
6 changes: 3 additions & 3 deletions src/parser.c
Expand Up @@ -277,7 +277,7 @@ init_log_item (GLog *glog) {
logitem->req = NULL;
logitem->resp_size = 0LL;
logitem->serve_time = 0;
logitem->status = 0;
logitem->status = -1;
logitem->time = NULL;
logitem->uniq_key = NULL;
logitem->vhost = NULL;
Expand Down Expand Up @@ -1109,14 +1109,14 @@ parse_specifier (GLogItem *logitem, const char **str, const char *p, const char
break;
/* Status Code */
case 's':
if (logitem->status)
if (logitem->status >= 0)
return handle_default_case_token (str, p);
if (!(tkn = parse_string (&(*str), end, 1)))
return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL);

logitem->status = strtol (tkn, &sEnd, 10);
if (tkn == sEnd || *sEnd != '\0' || errno == ERANGE ||
(!conf.no_strict_status && (logitem->status < 100 || logitem->status > 599))) {
(!conf.no_strict_status && !is_valid_http_status (logitem->status))) {
spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn);
free (tkn);
return 1;
Expand Down
34 changes: 26 additions & 8 deletions src/util.c
Expand Up @@ -61,7 +61,7 @@ pthread_mutex_t tz_mutex = PTHREAD_MUTEX_INITIALIZER;

/* HTTP status codes categories */
static const char *code_type[] = {
NULL,
STATUS_CODE_0XX,
STATUS_CODE_1XX,
STATUS_CODE_2XX,
STATUS_CODE_3XX,
Expand All @@ -71,25 +71,38 @@ static const char *code_type[] = {

/* HTTP status codes */
static const char *codes[1000] = {
[0] = STATUS_CODE_0,
[100] = STATUS_CODE_100, STATUS_CODE_101,
[200] = STATUS_CODE_200, STATUS_CODE_201, STATUS_CODE_202, STATUS_CODE_203, STATUS_CODE_204,
[205] = STATUS_CODE_205, STATUS_CODE_206, STATUS_CODE_207, STATUS_CODE_208,
[218] = STATUS_CODE_218,
[300] = STATUS_CODE_300, STATUS_CODE_301, STATUS_CODE_302, STATUS_CODE_303, STATUS_CODE_304,
[305] = STATUS_CODE_305, NULL, STATUS_CODE_307, STATUS_CODE_308,
[400] = STATUS_CODE_400, STATUS_CODE_401, STATUS_CODE_402, STATUS_CODE_403, STATUS_CODE_404,
[405] = STATUS_CODE_405, STATUS_CODE_406, STATUS_CODE_407, STATUS_CODE_408, STATUS_CODE_409,
[410] = STATUS_CODE_410, STATUS_CODE_411, STATUS_CODE_412, STATUS_CODE_413, STATUS_CODE_414,
[415] = STATUS_CODE_415, STATUS_CODE_416, STATUS_CODE_417, STATUS_CODE_418, NULL,
[420] = NULL, STATUS_CODE_421, STATUS_CODE_422, STATUS_CODE_423, STATUS_CODE_424,
[425] = NULL, STATUS_CODE_426, NULL, STATUS_CODE_428, STATUS_CODE_429,
[415] = STATUS_CODE_415, STATUS_CODE_416, STATUS_CODE_417, STATUS_CODE_418, STATUS_CODE_419,
[420] = STATUS_CODE_420, STATUS_CODE_421, STATUS_CODE_422, STATUS_CODE_423, STATUS_CODE_424,
[425] = NULL, STATUS_CODE_426, NULL, STATUS_CODE_428, STATUS_CODE_429, STATUS_CODE_430,
[431] = STATUS_CODE_431,
[440] = STATUS_CODE_440,
[444] = STATUS_CODE_444,
[449] = STATUS_CODE_449,
[450] = STATUS_CODE_450,
[451] = STATUS_CODE_451,
[460] = STATUS_CODE_460, STATUS_CODE_463, STATUS_CODE_464,
[494] = STATUS_CODE_494,
[495] = STATUS_CODE_495, STATUS_CODE_496, STATUS_CODE_497, NULL, STATUS_CODE_499,
[495] = STATUS_CODE_495, STATUS_CODE_496, STATUS_CODE_497, STATUS_CODE_498, STATUS_CODE_499,
[500] = STATUS_CODE_500, STATUS_CODE_501, STATUS_CODE_502, STATUS_CODE_503, STATUS_CODE_504,
[505] = STATUS_CODE_505,
[520] = STATUS_CODE_520, STATUS_CODE_521, STATUS_CODE_522, STATUS_CODE_523, STATUS_CODE_524,
[509] = STATUS_CODE_509,
[520] =
STATUS_CODE_520, STATUS_CODE_521, STATUS_CODE_522, STATUS_CODE_523, STATUS_CODE_524,
STATUS_CODE_525, STATUS_CODE_526, STATUS_CODE_527, STATUS_CODE_529,
[530] = STATUS_CODE_530,
[540] = STATUS_CODE_540,
[561] = STATUS_CODE_561,
[590] = STATUS_CODE_598, STATUS_CODE_599,
[999] = NULL
};

Expand Down Expand Up @@ -802,7 +815,7 @@ file_size (const char *filename) {
* On success, the status code type/category is returned. */
const char *
verify_status_code_type (int code) {
if (code < 100 || code > 599 || code_type[code / 100] == NULL)
if (code >= 0 && code <= 599 && code_type[code / 100] == NULL)
return "Unknown";

return code_type[code / 100];
Expand All @@ -815,12 +828,17 @@ verify_status_code_type (int code) {
* On success, the status code is returned. */
const char *
verify_status_code (int code) {
if (code < 100 || code > 599 || codes[code] == NULL)
if (code >= 0 && code <= 599 && code_type[code / 100] == NULL && codes[code] == NULL)
return "Unknown";

return codes[code];
}

int
is_valid_http_status (int code) {
return code >= 0 && code <= 599 && code_type[code / 100] != NULL && codes[code] != NULL;
}

/* Checks if the given string is within the given array.
*
* If not found, -1 is returned.
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Expand Up @@ -94,6 +94,7 @@ int ignore_referer (const char *host);
int intlen (uint64_t num);
int invalid_ipaddr (const char *str, int *ipvx);
int ip_in_range (const char *ip);
int is_valid_http_status (int code);
int ptr2int (char *ptr);
int str2int (const char *date);
int str_inarray (const char *s, const char *arr[], int size);
Expand Down

0 comments on commit d7c7dac

Please sign in to comment.