diff --git a/src/proto_htx.c b/src/proto_htx.c index 7a8101212..04afa1f1f 100644 --- a/src/proto_htx.c +++ b/src/proto_htx.c @@ -61,6 +61,7 @@ static int htx_stats_check_uri(struct stream *s, struct http_txn *txn, struct pr static int htx_handle_stats(struct stream *s, struct channel *req); static int htx_reply_100_continue(struct stream *s); +static int htx_reply_40x_unauthorized(struct stream *s, const char *auth_realm); /* This stream analyser waits for a complete HTTP request. It returns 1 if the * processing can continue on next analysers, or zero if it either needs more @@ -2759,11 +2760,10 @@ static enum rule_result htx_req_get_intercept_rule(struct proxy *px, struct list * 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); - txn->status = (txn->flags & TX_USE_PX_CONN) ? 407 : 401; - htx_reply_and_close(s, txn->status, &trash); - stream_inc_http_err_ctr(s); rule_ret = HTTP_RULE_RES_ABRT; + if (htx_reply_40x_unauthorized(s, auth_realm) == -1) + rule_ret = HTTP_RULE_RES_BADREQ; + stream_inc_http_err_ctr(s); goto end; case ACT_HTTP_REDIR: @@ -5281,6 +5281,78 @@ static int htx_reply_100_continue(struct stream *s) return -1; } + +/* Send a 401-Unauthorized or 407-Unauthorized response to the client, depending + * ont whether we use a proxy or not. It returns 0 on success and -1 on + * error. The response channel is updated accordingly. + */ +static int htx_reply_40x_unauthorized(struct stream *s, const char *auth_realm) +{ + struct channel *res = &s->res; + struct htx *htx = htx_from_buf(&res->buf); + struct htx_sl *sl; + struct ist code, body; + int status; + unsigned int flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11); + size_t data; + + if (!(s->txn->flags & TX_USE_PX_CONN)) { + status = 401; + code = ist("401"); + body = ist("