MINOR: http: split http_transform_header() function in two parts.
This function is a callback for HTTP actions. This function creates the replacement string from a build_logline() format and transform the header. This patch split this function in two part. With this modification, the header transformation and the replacement string are separed. We can now transform the header with another replacement string source than a build_logline() format.
This commit is contained in:
parent
b77aece24a
commit
5531f87ace
@ -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);
|
||||
|
@ -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 <rules> for session <s>, proxy <px> and
|
||||
* transaction <txn>. Returns the verdict of the first rule that prevents
|
||||
* further processing of the request (auth, deny, ...), and defaults to
|
||||
|
Loading…
x
Reference in New Issue
Block a user