Skip to content

Commit 24dd715

Browse files
committed
MINOR: http: don't %-encode the payload when not relevant
As reported by Pierre Maoui in GH #2477, it's not possible to render control chars from variables or expressions verbatim in the payload part of http-return statements. That's a problem because this part should not require to be encoded at all (we could even imagine building favicons on the fly for example). In fact it is the LOG_OPT_HTTP option when passed as default options on parse_logformat_string() which tells the log encoder that the payload should be http-encoded using lf_chunk() instead of being printed using the per-type encoder. This option was set when parsing logformat expressions for lf-string expression under http-return statements, as well as logformat expressions for set-map action. While it is true that those actions may only be used under http context, the LOG_OPT_HTTP logformat option is not relevant there, because the payload is expected to be used without being encoded. So let's simply get rid of this option when parsing logformat expressions for set-map action key/value and lf-string from http-request return action, and add a note next to LOG_OPT_HTTP option to indicate that it is used to tell the log encoder that the payload should be HTTP-encoded. Thanks to Pierre for having reported the issue and Willy for the analysis and patch proposal.
1 parent 97d3096 commit 24dd715

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

include/haproxy/log-t.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define LOG_OPT_QUOTE 0x00000004
4545
#define LOG_OPT_REQ_CAP 0x00000008
4646
#define LOG_OPT_RES_CAP 0x00000010
47-
#define LOG_OPT_HTTP 0x00000020
47+
#define LOG_OPT_HTTP 0x00000020 // forces http-encoding on the payload, incompatible with LOG_OPT_ENCODE
4848
#define LOG_OPT_ESC 0x00000040
4949
#define LOG_OPT_MERGE_SPACES 0x00000080
5050
#define LOG_OPT_BIN 0x00000100

src/http_act.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ static enum act_parse_ret parse_http_set_map(const char **args, int *orig_arg, s
19521952

19531953
/* key pattern */
19541954
lf_expr_init(&rule->arg.map.key);
1955-
if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.key, LOG_OPT_HTTP, cap, err)) {
1955+
if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.key, LOG_OPT_NONE, cap, err)) {
19561956
free(rule->arg.map.ref);
19571957
return ACT_RET_PRS_ERR;
19581958
}
@@ -1961,7 +1961,7 @@ static enum act_parse_ret parse_http_set_map(const char **args, int *orig_arg, s
19611961
/* value pattern for set-map only */
19621962
cur_arg++;
19631963
lf_expr_init(&rule->arg.map.value);
1964-
if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.value, LOG_OPT_HTTP, cap, err)) {
1964+
if (!parse_logformat_string(args[cur_arg], px, &rule->arg.map.value, LOG_OPT_NONE, cap, err)) {
19651965
free(rule->arg.map.ref);
19661966
return ACT_RET_PRS_ERR;
19671967
}

src/http_htx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ struct http_reply *http_parse_http_reply(const char **args, int *orig_arg, struc
17991799
memprintf(errmsg, "a content type must be defined with a log-format payload");
18001800
goto error;
18011801
}
1802-
if (!parse_logformat_string(obj, px, &reply->body.fmt, LOG_OPT_HTTP, cap, errmsg))
1802+
if (!parse_logformat_string(obj, px, &reply->body.fmt, LOG_OPT_NONE, cap, errmsg))
18031803
goto error;
18041804
}
18051805

0 commit comments

Comments
 (0)