]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proto-http: Add sample fetch wich returns all HTTP headers
authorThierry FOURNIER <thierry.fournier@ozon.io>
Wed, 19 Apr 2017 13:15:14 +0000 (15:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 27 Apr 2017 09:56:11 +0000 (11:56 +0200)
The sample fetch returns all headers including the last jump line.
The last jump line is used to determine if the block of headers is
truncated or not.

doc/configuration.txt
src/proto_http.c

index 1cb9b631e5adad5fc97be41e38c9d2a38ec962d6..bfce6b15f5d4d522bfdf5022e31510006f85dd2e 100644 (file)
@@ -14167,6 +14167,12 @@ payload_lv(<offset1>,<length>[,<offset2>]) : binary (deprecated)
   (eg: "stick on", "stick match"), and for "res.payload_lv" when used in the
   context of a response such as in "stick store response".
 
+req.hdrs : string
+  Returns the current request headers as string including the last empty line
+  separating headers from the request body. The last empty line can be used to
+  detect a truncated header block. This sample fetch is useful for some SPOE
+  headers analyzers and for advanced logging.
+
 req.hdrs_bin : binary
   Returns the current request headers contained in preparsed binary form. This
   is useful for offloading some processing with SPOE. Each string is described
index 2dd2ad4fb9fa1f5659a43f75768045af52629c87..579473ba04edc5e25c92cb179e2a51badd2fa054 100644 (file)
@@ -10437,6 +10437,31 @@ smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const char *kw, v
        return 1;
 }
 
+/* Returns a string block containing all headers including the
+ * empty line wich separes headers from the body. This is useful
+ * form some headers analysis.
+ */
+static int
+smp_fetch_hdrs(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       struct http_msg *msg;
+       struct hdr_idx *idx;
+       struct http_txn *txn;
+
+       CHECK_HTTP_MESSAGE_FIRST();
+
+       txn = smp->strm->txn;
+       idx = &txn->hdr_idx;
+       msg = &txn->req;
+
+       smp->data.type = SMP_T_STR;
+       smp->data.u.str.str = msg->chn->buf->p + hdr_idx_first_pos(idx);
+       smp->data.u.str.len = msg->eoh - hdr_idx_first_pos(idx) + 1 +
+                             (msg->chn->buf->p[msg->eoh] == '\r');
+
+       return 1;
+}
+
 /* Returns the header request in a length/value encoded format.
  * This is useful for exchanges with the SPOE.
  *
@@ -13457,6 +13482,7 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
        { "req.body_size",   smp_fetch_body_size,      0,                NULL,    SMP_T_SINT, SMP_USE_HRQHV },
        { "req.body_param",  smp_fetch_body_param,     ARG1(0,STR),      NULL,    SMP_T_BIN,  SMP_USE_HRQHV },
 
+       { "req.hdrs",        smp_fetch_hdrs,           0,                NULL,    SMP_T_BIN,  SMP_USE_HRQHV },
        { "req.hdrs_bin",    smp_fetch_hdrs_bin,       0,                NULL,    SMP_T_BIN,  SMP_USE_HRQHV },
 
        /* HTTP version on the response path */