diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h index 080dc58c0..452ffdd0f 100644 --- a/include/proto/proto_http.h +++ b/include/proto/proto_http.h @@ -101,6 +101,9 @@ int http_remove_header2(struct http_msg *msg, struct hdr_idx *idx, struct hdr_ct int http_header_add_tail2(struct http_msg *msg, struct hdr_idx *hdr_idx, const char *text, int len); int http_replace_req_line(int action, const char *replace, int len, struct proxy *px, struct session *s, struct http_txn *txn); +int http_transform_header_str(struct session* s, struct http_msg *msg, const char* name, + unsigned int name_len, const char *str, struct my_regex *re, + int action); void http_sess_log(struct session *s); void http_perform_server_redirect(struct session *s, struct stream_interface *si); void http_return_srv_error(struct session *s, struct stream_interface *si); diff --git a/src/proto_http.c b/src/proto_http.c index 029b46ba4..8ad15643a 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -3246,23 +3246,18 @@ static inline void inet_set_tos(int fd, struct sockaddr_storage from, int tos) #endif } -static int http_transform_header(struct session* s, struct http_msg *msg, - const char* name, unsigned int name_len, - struct list *fmt, struct my_regex *re, - int action) +int http_transform_header_str(struct session* s, struct http_msg *msg, + const char* name, unsigned int name_len, + const char *str, struct my_regex *re, + int action) { - int (*http_find_hdr_func)(const char *name, int len, char *sol, - struct hdr_idx *idx, struct hdr_ctx *ctx); struct hdr_ctx ctx; char *buf = msg->chn->buf->p; struct hdr_idx *idx = &s->txn.hdr_idx; - struct chunk *replace = get_trash_chunk(); + int (*http_find_hdr_func)(const char *name, int len, char *sol, + struct hdr_idx *idx, struct hdr_ctx *ctx); struct chunk *output = get_trash_chunk(); - replace->len = build_logline(s, replace->str, replace->size, fmt); - if (replace->len >= replace->size - 1) - return -1; - ctx.idx = 0; /* Choose the header browsing function. */ @@ -3288,7 +3283,7 @@ static int http_transform_header(struct session* s, struct http_msg *msg, if (!regex_exec_match2(re, val, val_end-val, MAX_MATCH, pmatch, 0)) continue; - output->len = exp_replace(output->str, output->size, val, replace->str, pmatch); + output->len = exp_replace(output->str, output->size, val, str, pmatch); if (output->len == -1) return -1; @@ -3304,6 +3299,20 @@ static int http_transform_header(struct session* s, struct http_msg *msg, return 0; } +static int http_transform_header(struct session* s, struct http_msg *msg, + const char* name, unsigned int name_len, + struct list *fmt, struct my_regex *re, + int action) +{ + struct chunk *replace = get_trash_chunk(); + + replace->len = build_logline(s, replace->str, replace->size, fmt); + if (replace->len >= replace->size - 1) + return -1; + + return http_transform_header_str(s, msg, name, name_len, replace->str, re, action); +} + /* Executes the http-request rules for session , proxy and * transaction . Returns the verdict of the first rule that prevents * further processing of the request (auth, deny, ...), and defaults to