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];
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);
#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);
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 */
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);
#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>
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;
}
}
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;
}
}
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();
* 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);
[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");
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;
-}
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
#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
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;
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);
http_err_codes[rc]);
err_code |= ERR_ALERT | ERR_FATAL;
}
- htx_err_chunks[rc] = chk;
+ http_err_chunks[rc] = chk;
}
end:
return err_code;