While creating the patch I noticed that I used 1.8-dev0 tag which can be downloaded as tar.gz file. I now used the master branch, added my changes, did a commit and exported the changes via patch. Don't worry, I restarted HAProxy and checked if my custom 401 error pages are still working (they are ;) ).

Patch is attached, I hope everything is correct :)

Am 11.02.2017 um 21:18 schrieb Robin H. Johnson:
On Sat, Feb 11, 2017 at 07:17:20PM +0100, Michael Hamburger wrote:
If you nonetheless like a git patch I will try to send one.
Please do send a patch, it's a LOT easier to review, and if it's good,
it can be applied with your name on it :-).

If you have all of your changes in a single commit, and that commit is
the head of your branch, then you can do 'git format-patch HEAD^', and
then either use git send-email, or just attach the patch to an email.


>From fcdb11dccf27b4cd18e37f894e1ebbb5a31e1ccb Mon Sep 17 00:00:00 2001
From: hamburml <[email protected]>
Date: Sat, 11 Feb 2017 21:49:47 +0100
Subject: [PATCH] Feature: Allow dynamic http status page 401 and 407
X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4

---
 include/types/proto_http.h |  2 ++
 src/proto_http.c           | 42 +++++++++++++++++++++---------------------
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/include/types/proto_http.h b/include/types/proto_http.h
index 66f7397..ebc9016 100644
--- a/include/types/proto_http.h
+++ b/include/types/proto_http.h
@@ -245,8 +245,10 @@ enum rule_result {
 enum {
        HTTP_ERR_200 = 0,
        HTTP_ERR_400,
+       HTTP_ERR_401,
        HTTP_ERR_403,
        HTTP_ERR_405,
+       HTTP_ERR_407,
        HTTP_ERR_408,
        HTTP_ERR_429,
        HTTP_ERR_500,
diff --git a/src/proto_http.c b/src/proto_http.c
index 5ad2956..df947df 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -113,31 +113,13 @@ const char *HTTP_308 =
        "Content-length: 0\r\n"
        "Location: "; /* not terminated since it will be concatenated with the 
URL */
 
-/* Warning: this one is an sprintf() fmt string, with <realm> as its only 
argument */
-const char *HTTP_401_fmt =
-       "HTTP/1.0 401 Unauthorized\r\n"
-       "Cache-Control: no-cache\r\n"
-       "Connection: close\r\n"
-       "Content-Type: text/html\r\n"
-       "WWW-Authenticate: Basic realm=\"%s\"\r\n"
-       "\r\n"
-       "<html><body><h1>401 Unauthorized</h1>\nYou need a valid user and 
password to access this content.\n</body></html>\n";
-
-const char *HTTP_407_fmt =
-       "HTTP/1.0 407 Unauthorized\r\n"
-       "Cache-Control: no-cache\r\n"
-       "Connection: close\r\n"
-       "Content-Type: text/html\r\n"
-       "Proxy-Authenticate: Basic realm=\"%s\"\r\n"
-       "\r\n"
-       "<html><body><h1>407 Unauthorized</h1>\nYou need a valid user and 
password to access this content.\n</body></html>\n";
-
-
 const int http_err_codes[HTTP_ERR_SIZE] = {
        [HTTP_ERR_200] = 200,  /* used by "monitor-uri" */
        [HTTP_ERR_400] = 400,
+       [HTTP_ERR_401] = 401,
        [HTTP_ERR_403] = 403,
        [HTTP_ERR_405] = 405,
+       [HTTP_ERR_407] = 407,
        [HTTP_ERR_408] = 408,
        [HTTP_ERR_429] = 429,
        [HTTP_ERR_500] = 500,
@@ -162,6 +144,15 @@ static const char *http_err_msgs[HTTP_ERR_SIZE] = {
        "Content-Type: text/html\r\n"
        "\r\n"
        "<html><body><h1>400 Bad request</h1>\nYour browser sent an invalid 
request.\n</body></html>\n",
+       
+       [HTTP_ERR_401] =
+       "HTTP/1.0 401 Unauthorized\r\n"
+       "Cache-Control: no-cache\r\n"
+       "Connection: close\r\n"
+       "Content-Type: text/html\r\n"
+       "WWW-Authenticate: Basic realm=\"%s\"\r\n"
+       "\r\n"
+       "<html><body><h1>401 Unauthorized</h1>\nYou need a valid user and 
password to access this content.\n</body></html>\n",
 
        [HTTP_ERR_403] =
        "HTTP/1.0 403 Forbidden\r\n"
@@ -178,6 +169,15 @@ static const char *http_err_msgs[HTTP_ERR_SIZE] = {
        "Content-Type: text/html\r\n"
        "\r\n"
        "<html><body><h1>405 Method Not Allowed</h1>\nA request was made of a 
resource using a request method not supported by that 
resource\n</body></html>\n",
+       
+       [HTTP_ERR_407] =
+       "HTTP/1.0 407 Unauthorized\r\n"
+       "Cache-Control: no-cache\r\n"
+       "Connection: close\r\n"
+       "Content-Type: text/html\r\n"
+       "Proxy-Authenticate: Basic realm=\"%s\"\r\n"
+       "\r\n"
+       "<html><body><h1>407 Unauthorized</h1>\nYou need a valid user and 
password to access this content.\n</body></html>\n",
 
        [HTTP_ERR_408] =
        "HTTP/1.0 408 Request Time-out\r\n"
@@ -3517,7 +3517,7 @@ resume_execution:
                         * count one error, because normal browsing won't 
significantly
                         * increase the counter but brute force attempts will.
                         */
-                       chunk_printf(&trash, (txn->flags & TX_USE_PX_CONN) ? 
HTTP_407_fmt : HTTP_401_fmt, auth_realm);
+                       chunk_printf(&trash, (txn->flags & TX_USE_PX_CONN) ? 
(const char *)http_error_message(s, HTTP_ERR_407)->str : (const char 
*)http_error_message(s, HTTP_ERR_401)->str, auth_realm);
                        txn->status = (txn->flags & TX_USE_PX_CONN) ? 407 : 401;
                        http_reply_and_close(s, txn->status, &trash);
                        stream_inc_http_err_ctr(s);
-- 
2.10.0.windows.1

Reply via email to