From: Thierry FOURNIER Date: Wed, 19 Apr 2017 13:15:14 +0000 (+0200) Subject: MINOR: proto-http: Add sample fetch wich returns all HTTP headers X-Git-Tag: v1.8-dev2~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d7d8881543a1eb1be91207e7b811ef5f9df0eddd;p=thirdparty%2Fhaproxy.git MINOR: proto-http: Add sample fetch wich returns all HTTP headers 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. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 1cb9b631e5..bfce6b15f5 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -14167,6 +14167,12 @@ payload_lv(,[,]) : 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 diff --git a/src/proto_http.c b/src/proto_http.c index 2dd2ad4fb9..579473ba04 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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 */