mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-03 01:49:24 +00:00
MINOR: http: Don't store raw HTTP errors in chunks anymore
Default HTTP error messages are stored in an array of chunks. And since the HTX was added, these messages are also converted in HTX and stored in another array. But now, the first array is not used anymore because the legacy HTTP mode was removed. So now, only the array with the HTX messages are kept. The other one was removed.
This commit is contained in:
parent
41ba36f8b2
commit
f734638976
@ -120,7 +120,6 @@ struct http_method_desc {
|
||||
|
||||
extern const int http_err_codes[HTTP_ERR_SIZE];
|
||||
extern const char *http_err_msgs[HTTP_ERR_SIZE];
|
||||
extern struct buffer http_err_chunks[HTTP_ERR_SIZE];
|
||||
extern const struct ist http_known_methods[HTTP_METH_OTHER];
|
||||
extern const uint8_t http_char_classes[256];
|
||||
|
||||
@ -134,7 +133,6 @@ extern const char *HTTP_308;
|
||||
extern const char *HTTP_401_fmt;
|
||||
extern const char *HTTP_407_fmt;
|
||||
|
||||
int init_http(char **err);
|
||||
enum http_meth_t find_http_meth(const char *str, const int len);
|
||||
int http_get_status_idx(unsigned int status);
|
||||
const char *http_get_reason(unsigned int status);
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include <types/http_htx.h>
|
||||
|
||||
extern struct buffer htx_err_chunks[HTTP_ERR_SIZE];
|
||||
extern struct buffer http_err_chunks[HTTP_ERR_SIZE];
|
||||
|
||||
struct htx_sl *http_get_stline(struct htx *htx);
|
||||
int http_find_header(const struct htx *htx, const struct ist name, struct http_hdr_ctx *ctx, int full);
|
||||
@ -47,5 +47,6 @@ unsigned int http_get_htx_hdr(const struct htx *htx, const struct ist hdr,
|
||||
int occ, struct http_hdr_ctx *ctx, char **vptr, size_t *vlen);
|
||||
unsigned int http_get_htx_fhdr(const struct htx *htx, const struct ist hdr,
|
||||
int occ, struct http_hdr_ctx *ctx, char **vptr, size_t *vlen);
|
||||
struct htx *http_str_to_htx(struct buffer *buf, struct ist raw);
|
||||
|
||||
#endif /* _PROTO_HTTP_HTX_H */
|
||||
|
@ -963,7 +963,7 @@ static void http_cache_io_handler(struct appctx *appctx)
|
||||
error:
|
||||
/* Sent and HTTP error 500 */
|
||||
b_reset(&res->buf);
|
||||
errmsg = &htx_err_chunks[HTTP_ERR_500];
|
||||
errmsg = &http_err_chunks[HTTP_ERR_500];
|
||||
res->buf.data = b_data(errmsg);
|
||||
memcpy(res->buf.area, b_head(errmsg), b_data(errmsg));
|
||||
res_htx = htx_from_buf(&res->buf);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <proto/acl.h>
|
||||
#include <proto/checks.h>
|
||||
#include <proto/connection.h>
|
||||
#include <proto/http_htx.h>
|
||||
#include <proto/http_rules.h>
|
||||
#include <proto/listener.h>
|
||||
#include <proto/protocol.h>
|
||||
@ -3832,8 +3833,17 @@ stats_error_parsing:
|
||||
|
||||
for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
|
||||
if (http_err_codes[rc] == errnum) {
|
||||
struct buffer chk;
|
||||
|
||||
if (!http_str_to_htx(&chk, ist2(err, errlen))) {
|
||||
ha_alert("parsing [%s:%d] : unable to convert message in HTX for HTTP return code %d.\n",
|
||||
file, linenum, http_err_codes[rc]);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
free(err);
|
||||
goto out;
|
||||
}
|
||||
chunk_destroy(&curproxy->errmsg[rc]);
|
||||
chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
|
||||
curproxy->errmsg[rc] = chk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -3892,8 +3902,17 @@ stats_error_parsing:
|
||||
errnum = atol(args[1]);
|
||||
for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
|
||||
if (http_err_codes[rc] == errnum) {
|
||||
struct buffer chk;
|
||||
|
||||
if (!http_str_to_htx(&chk, ist2(err, errlen))) {
|
||||
ha_alert("parsing [%s:%d] : unable to convert message in HTX for HTTP return code %d.\n",
|
||||
file, linenum, http_err_codes[rc]);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
free(err);
|
||||
goto out;
|
||||
}
|
||||
chunk_destroy(&curproxy->errmsg[rc]);
|
||||
chunk_initlen(&curproxy->errmsg[rc], err, errlen, errlen);
|
||||
curproxy->errmsg[rc] = chk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1383,13 +1383,6 @@ static void init(int argc, char **argv)
|
||||
if (init_acl() != 0)
|
||||
exit(1);
|
||||
|
||||
/* warning, we init buffers later */
|
||||
if (!init_http(&err_msg)) {
|
||||
ha_alert("%s. Aborting.\n", err_msg);
|
||||
free(err_msg);
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Initialise lua. */
|
||||
hlua_init();
|
||||
|
||||
|
@ -6724,7 +6724,7 @@ static void hlua_applet_http_fct(struct appctx *ctx)
|
||||
* just close the connection.
|
||||
*/
|
||||
if (!(ctx->ctx.hlua_apphttp.flags & APPLET_HDR_SENT)) {
|
||||
struct buffer *err = &htx_err_chunks[HTTP_ERR_500];
|
||||
struct buffer *err = &http_err_chunks[HTTP_ERR_500];
|
||||
|
||||
channel_erase(res);
|
||||
res->buf.data = b_data(err);
|
||||
|
25
src/http.c
25
src/http.c
@ -155,11 +155,6 @@ const unsigned char http_char_classes[256] = {
|
||||
[127] = HTTP_FLG_CTL,
|
||||
};
|
||||
|
||||
/* We must put the messages here since GCC cannot initialize consts depending
|
||||
* on strlen().
|
||||
*/
|
||||
struct buffer http_err_chunks[HTTP_ERR_SIZE];
|
||||
|
||||
const struct ist HTTP_100 = IST("HTTP/1.1 100 Continue\r\n\r\n");
|
||||
|
||||
const struct ist HTTP_103 = IST("HTTP/1.1 103 Early Hints\r\n");
|
||||
@ -985,23 +980,3 @@ int http_parse_stline(const struct ist line, struct ist *p1, struct ist *p2, str
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* post-initializes the HTTP parts. Returns zero on error, with <err>
|
||||
* pointing to the error message.
|
||||
*/
|
||||
int init_http(char **err)
|
||||
{
|
||||
int msg;
|
||||
|
||||
for (msg = 0; msg < HTTP_ERR_SIZE; msg++) {
|
||||
if (!http_err_msgs[msg]) {
|
||||
memprintf(err, "Internal error: no message defined for HTTP return code %d", msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
http_err_chunks[msg].area = (char *)http_err_msgs[msg];
|
||||
http_err_chunks[msg].data = strlen(http_err_msgs[msg]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -4904,7 +4904,7 @@ struct buffer *http_error_message(struct stream *s)
|
||||
else if (strm_fe(s)->errmsg[msgnum].area)
|
||||
return &strm_fe(s)->errmsg[msgnum];
|
||||
else
|
||||
return &htx_err_chunks[msgnum];
|
||||
return &http_err_chunks[msgnum];
|
||||
}
|
||||
|
||||
/* Return the error message corresponding to si->err_type. It is assumed
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <proto/http_htx.h>
|
||||
|
||||
struct buffer htx_err_chunks[HTTP_ERR_SIZE];
|
||||
struct buffer http_err_chunks[HTTP_ERR_SIZE];
|
||||
|
||||
/* Returns the next unporocessed start line in the HTX message. It returns NULL
|
||||
* if the start-line is undefined (first == -1). Otherwise, it returns the
|
||||
@ -600,7 +600,7 @@ unsigned int http_get_htx_fhdr(const struct htx *htx, const struct ist hdr,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct htx *http_str_to_htx(struct buffer *buf, struct ist raw)
|
||||
struct htx *http_str_to_htx(struct buffer *buf, struct ist raw)
|
||||
{
|
||||
struct htx *htx;
|
||||
struct htx_sl *sl;
|
||||
@ -673,28 +673,11 @@ error:
|
||||
|
||||
static int http_htx_init(void)
|
||||
{
|
||||
struct proxy *px;
|
||||
struct buffer chk;
|
||||
struct ist raw;
|
||||
int rc;
|
||||
int err_code = 0;
|
||||
|
||||
for (px = proxies_list; px; px = px->next) {
|
||||
for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
|
||||
if (!b_data(&px->errmsg[rc]))
|
||||
continue;
|
||||
|
||||
raw = ist2(b_head(&px->errmsg[rc]), b_data(&px->errmsg[rc]));
|
||||
if (!http_str_to_htx(&chk, raw)) {
|
||||
ha_alert("config: %s '%s': Unable to convert message in HTX for HTTP return code %d.\n",
|
||||
proxy_type_str(px), px->id, http_err_codes[rc]);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
chunk_destroy(&px->errmsg[rc]);
|
||||
px->errmsg[rc] = chk;
|
||||
}
|
||||
}
|
||||
|
||||
for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
|
||||
if (!http_err_msgs[rc]) {
|
||||
ha_alert("Internal error: no message defined for HTTP return code %d", rc);
|
||||
@ -708,7 +691,7 @@ static int http_htx_init(void)
|
||||
http_err_codes[rc]);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
htx_err_chunks[rc] = chk;
|
||||
http_err_chunks[rc] = chk;
|
||||
}
|
||||
end:
|
||||
return err_code;
|
||||
|
Loading…
Reference in New Issue
Block a user