Welcome! Log In Create A New Profile

Advanced

[PATCH] Added dark mode support to error pages - request in ticket #2434

J Carter
January 28, 2023 06:16PM
Hello,

An example of the dark mode and light mode pages is here
https://imgur.com/a/n9QJpp4

# HG changeset patch
# User jordanc.carter@outlook.com
# Date 1674945436 0
# Sat Jan 28 22:37:16 2023 +0000
# Branch dark-error
# Node ID 0dcba21038765f6f03098cbdf23f401e89e3648f
# Parent 07b0bee87f32be91a33210bc06973e07c4c1dac9
Added dark mode support to error pages - request in ticket #2434

diff -r 07b0bee87f32 -r 0dcba2103876 src/http/ngx_http_special_response.c
--- a/src/http/ngx_http_special_response.c Wed Dec 21 14:53:27 2022 +0300
+++ b/src/http/ngx_http_special_response.c Sat Jan 28 22:37:16 2023 +0000
@@ -18,6 +18,27 @@
static ngx_int_t ngx_http_send_refresh(ngx_http_request_t *r);
+#define ngx_error_page_head(MESSAGE) \
+"<html>" CRLF \
+"<head>" CRLF \
+"<title>" MESSAGE "</title>" CRLF \
+"<meta name=\"color-scheme\" content=\"light dark\"/>" CRLF \
+"</head>" CRLF \
+"<body>" CRLF \
+"<center><h1>" MESSAGE "</h1></center>" CRLF
+
+
+#define ngx_error_page_head_br(MESSAGE) \
+"<html>" CRLF \
+"<head>" CRLF \
+"<title>400" MESSAGE "</title>" CRLF \
+"<meta name=\"color-scheme\" content=\"light dark\"/>" CRLF \
+"</head>" CRLF \
+"<body>" CRLF \
+"<center><h1>400 Bad Request</h1></center>" CRLF \
+"<center>" MESSAGE "</center>" CRLF
+
+
static u_char ngx_http_error_full_tail[] =
"<hr><center>" NGINX_VER "</center>" CRLF
"</body>" CRLF
@@ -57,284 +78,140 @@
"\"></head><body></body></html>" CRLF;
-static char ngx_http_error_301_page[] =
-"<html>" CRLF
-"<head><title>301 Moved Permanently</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>301 Moved Permanently</h1></center>" CRLF
-;
+static char ngx_http_error_301_page[] = + ngx_error_page_head("301
Moved Permanently");
static char ngx_http_error_302_page[] =
-"<html>" CRLF
-"<head><title>302 Found</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>302 Found</h1></center>" CRLF
-;
+ ngx_error_page_head("302 Found");
static char ngx_http_error_303_page[] =
-"<html>" CRLF
-"<head><title>303 See Other</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>303 See Other</h1></center>" CRLF
-;
+ ngx_error_page_head("303 See Other");
static char ngx_http_error_307_page[] =
-"<html>" CRLF
-"<head><title>307 Temporary Redirect</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>307 Temporary Redirect</h1></center>" CRLF
-;
+ ngx_error_page_head("307 Temporary Redirect");
static char ngx_http_error_308_page[] =
-"<html>" CRLF
-"<head><title>308 Permanent Redirect</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>308 Permanent Redirect</h1></center>" CRLF
-;
+ ngx_error_page_head("308 Permanent Redirect");
static char ngx_http_error_400_page[] =
-"<html>" CRLF
-"<head><title>400 Bad Request</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>400 Bad Request</h1></center>" CRLF
-;
+ ngx_error_page_head("400 Bad Request");
static char ngx_http_error_401_page[] =
-"<html>" CRLF
-"<head><title>401 Authorization Required</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>401 Authorization Required</h1></center>" CRLF
-;
+ ngx_error_page_head("401 Authorization Required");
static char ngx_http_error_402_page[] =
-"<html>" CRLF
-"<head><title>402 Payment Required</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>402 Payment Required</h1></center>" CRLF
-;
+ ngx_error_page_head("402 Payment Required");
static char ngx_http_error_403_page[] =
-"<html>" CRLF
-"<head><title>403 Forbidden</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>403 Forbidden</h1></center>" CRLF
-;
+ ngx_error_page_head("403 Forbidden");
static char ngx_http_error_404_page[] =
-"<html>" CRLF
-"<head><title>404 Not Found</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>404 Not Found</h1></center>" CRLF
-;
+ ngx_error_page_head("404 Not Found");
static char ngx_http_error_405_page[] =
-"<html>" CRLF
-"<head><title>405 Not Allowed</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>405 Not Allowed</h1></center>" CRLF
-;
+ ngx_error_page_head("405 Not Allowed");
static char ngx_http_error_406_page[] =
-"<html>" CRLF
-"<head><title>406 Not Acceptable</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>406 Not Acceptable</h1></center>" CRLF
-;
+ ngx_error_page_head("406 Not Acceptable");
static char ngx_http_error_408_page[] =
-"<html>" CRLF
-"<head><title>408 Request Time-out</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>408 Request Time-out</h1></center>" CRLF
-;
+ ngx_error_page_head("408 Request Time-out");
static char ngx_http_error_409_page[] =
-"<html>" CRLF
-"<head><title>409 Conflict</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>409 Conflict</h1></center>" CRLF
-;
+ ngx_error_page_head("409 Conflict");
static char ngx_http_error_410_page[] =
-"<html>" CRLF
-"<head><title>410 Gone</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>410 Gone</h1></center>" CRLF
-;
+ ngx_error_page_head("410 Gone");
static char ngx_http_error_411_page[] =
-"<html>" CRLF
-"<head><title>411 Length Required</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>411 Length Required</h1></center>" CRLF
-;
+ ngx_error_page_head("411 Length Required");
static char ngx_http_error_412_page[] =
-"<html>" CRLF
-"<head><title>412 Precondition Failed</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>412 Precondition Failed</h1></center>" CRLF
-;
+ ngx_error_page_head("412 Precondition Failed");
static char ngx_http_error_413_page[] =
-"<html>" CRLF
-"<head><title>413 Request Entity Too Large</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>413 Request Entity Too Large</h1></center>" CRLF
-;
+ ngx_error_page_head("413 Request Entity Too Large");
static char ngx_http_error_414_page[] =
-"<html>" CRLF
-"<head><title>414 Request-URI Too Large</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>414 Request-URI Too Large</h1></center>" CRLF
-;
+ ngx_error_page_head("414 Request-URI Too Large");
static char ngx_http_error_415_page[] =
-"<html>" CRLF
-"<head><title>415 Unsupported Media Type</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>415 Unsupported Media Type</h1></center>" CRLF
-;
+ ngx_error_page_head("415 Unsupported Media Type");
static char ngx_http_error_416_page[] =
-"<html>" CRLF
-"<head><title>416 Requested Range Not Satisfiable</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>416 Requested Range Not Satisfiable</h1></center>" CRLF
-;
+ ngx_error_page_head("416 Requested Range Not Satisfiable");
static char ngx_http_error_421_page[] =
-"<html>" CRLF
-"<head><title>421 Misdirected Request</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>421 Misdirected Request</h1></center>" CRLF
-;
+ ngx_error_page_head("421 Misdirected Request");
static char ngx_http_error_429_page[] =
-"<html>" CRLF
-"<head><title>429 Too Many Requests</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>429 Too Many Requests</h1></center>" CRLF
-;
+ ngx_error_page_head("429 Too Many Requests");
-static char ngx_http_error_494_page[] =
-"<html>" CRLF
-"<head><title>400 Request Header Or Cookie Too Large</title></head>"
-CRLF
-"<body>" CRLF
-"<center><h1>400 Bad Request</h1></center>" CRLF
-"<center>Request Header Or Cookie Too Large</center>" CRLF
-;
+static char ngx_http_error_494_page[] = +
ngx_error_page_head_br("Request Header Or Cookie Too Large");
-static char ngx_http_error_495_page[] =
-"<html>" CRLF
-"<head><title>400 The SSL certificate error</title></head>"
-CRLF
-"<body>" CRLF
-"<center><h1>400 Bad Request</h1></center>" CRLF
-"<center>The SSL certificate error</center>" CRLF
-;
+static char ngx_http_error_495_page[] = + ngx_error_page_head_br("The
SSL certificate error"); static char ngx_http_error_496_page[] =
-"<html>" CRLF
-"<head><title>400 No required SSL certificate was sent</title></head>"
-CRLF
-"<body>" CRLF
-"<center><h1>400 Bad Request</h1></center>" CRLF
-"<center>No required SSL certificate was sent</center>" CRLF
-;
+ ngx_error_page_head_br("No required SSL certificate was sent"); static
char ngx_http_error_497_page[] =
-"<html>" CRLF
-"<head><title>400 The plain HTTP request was sent to HTTPS
port</title></head>"
-CRLF
-"<body>" CRLF
-"<center><h1>400 Bad Request</h1></center>" CRLF
-"<center>The plain HTTP request was sent to HTTPS port</center>" CRLF
-;
+ ngx_error_page_head_br("The plain HTTP request was sent to HTTPS
port"); static char ngx_http_error_500_page[] =
-"<html>" CRLF
-"<head><title>500 Internal Server Error</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>500 Internal Server Error</h1></center>" CRLF
-;
+ ngx_error_page_head("500 Internal Server Error");
static char ngx_http_error_501_page[] =
-"<html>" CRLF
-"<head><title>501 Not Implemented</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>501 Not Implemented</h1></center>" CRLF
-;
+ ngx_error_page_head("501 Not Implemented");
static char ngx_http_error_502_page[] =
-"<html>" CRLF
-"<head><title>502 Bad Gateway</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>502 Bad Gateway</h1></center>" CRLF
-;
+ ngx_error_page_head("502 Bad Gateway");
static char ngx_http_error_503_page[] =
-"<html>" CRLF
-"<head><title>503 Service Temporarily Unavailable</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>503 Service Temporarily Unavailable</h1></center>" CRLF
-;
+ ngx_error_page_head("503 Service Temporarily Unavailabley");
static char ngx_http_error_504_page[] =
-"<html>" CRLF
-"<head><title>504 Gateway Time-out</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>504 Gateway Time-out</h1></center>" CRLF
-;
+ ngx_error_page_head("504 Gateway Time-out");
static char ngx_http_error_505_page[] =
-"<html>" CRLF
-"<head><title>505 HTTP Version Not Supported</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>505 HTTP Version Not Supported</h1></center>" CRLF
-;
+ ngx_error_page_head("505 HTTP Version Not Supported");
static char ngx_http_error_507_page[] =
-"<html>" CRLF
-"<head><title>507 Insufficient Storage</title></head>" CRLF
-"<body>" CRLF
-"<center><h1>507 Insufficient Storage</h1></center>" CRLF
-;
+ ngx_error_page_head("507 Insufficient Storage");
static ngx_str_t ngx_http_error_pages[] = {


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Added dark mode support to error pages - request in ticket #2434

J Carter 304 January 28, 2023 06:16PM

Re: [PATCH] Added dark mode support to error pages - request in ticket #2434

J Carter 158 January 28, 2023 07:36PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 188
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready