]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: split http_transform_header() function in two parts.
authorThierry FOURNIER <tfournier@haproxy.com>
Mon, 16 Mar 2015 10:15:50 +0000 (11:15 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 18 Mar 2015 10:34:06 +0000 (11:34 +0100)
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.

include/proto/proto_http.h
src/proto_http.c

index 080dc58c0cafd26c5f9e12a535bc947ca0fcaae8..452ffdd0f2d7e31f49c818bb5c28c429dfbdca71 100644 (file)
@@ -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);
index 029b46ba4108feb4d41fb3d55969922c8bf31758..8ad15643aae4da87624b026e4dc488e110f029da 100644 (file)
@@ -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