]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: add capture.req.ver and capture.res.ver
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Apr 2014 21:41:57 +0000 (23:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Apr 2014 21:41:57 +0000 (23:41 +0200)
These ones report a string as "HTTP/1.0" or "HTTP/1.1" depending on the
version of the request message or the response message, respectively.
The purpose is to be able to emit custom log lines reporting this version
in a persistent way.

doc/configuration.txt
src/proto_http.c

index 3c245abada966222589cf66bb5164de42292a130..610a6744428369f092352ea3c036a32b6d2d6853 100644 (file)
@@ -10698,12 +10698,22 @@ capture.req.uri : string
   and "url", it can be used in both request and response because it's
   allocated.
 
+capture.req.ver : string
+  This extracts the request's HTTP version and returns either "HTTP/1.0" or
+  "HTTP/1.1". Unlike "req.ver", it can be used in both request, response, and
+  logs because it relies on a persistent flag.
+
 capture.res.hdr(<idx>) : string
   This extracts the content of the header captured by the "capture response
   header", idx is the position of the capture keyword in the configuration.
   The first entry is an index of 0.
   See also: "capture response header"
 
+capture.res.ver : string
+  This extracts the response's HTTP version and returns either "HTTP/1.0" or
+  "HTTP/1.1". Unlike "res.ver", it can be used in logs because it relies on a
+  persistent flag.
+
 req.cook([<name>]) : string
 cook([<name>]) : string (deprecated)
   This extracts the last occurrence of the cookie name <name> on a "Cookie"
index 6edf11355de8a01e6ad74c17019afb71da73d037..8d42a1d50bb9a8beba50f8784078f3ff797e8dd1 100644 (file)
@@ -10033,6 +10033,54 @@ smp_fetch_capture_req_uri(struct proxy *px, struct session *l4, void *l7, unsign
        return 1;
 }
 
+/* Retrieves the HTTP version from the request (either 1.0 or 1.1) and emits it
+ * as a string (either "HTTP/1.0" or "HTTP/1.1").
+ */
+static int
+smp_fetch_capture_req_ver(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+                          const struct arg *args, struct sample *smp, const char *kw)
+{
+       struct http_txn *txn = l7;
+
+       if (txn->req.msg_state < HTTP_MSG_HDR_FIRST)
+               return 0;
+
+       if (txn->req.flags & HTTP_MSGF_VER_11)
+               smp->data.str.str = "HTTP/1.1";
+       else
+               smp->data.str.str = "HTTP/1.0";
+
+       smp->data.str.len = 8;
+       smp->type  = SMP_T_STR;
+       smp->flags = SMP_F_CONST;
+       return 1;
+
+}
+
+/* Retrieves the HTTP version from the response (either 1.0 or 1.1) and emits it
+ * as a string (either "HTTP/1.0" or "HTTP/1.1").
+ */
+static int
+smp_fetch_capture_res_ver(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+                          const struct arg *args, struct sample *smp, const char *kw)
+{
+       struct http_txn *txn = l7;
+
+       if (txn->rsp.msg_state < HTTP_MSG_HDR_FIRST)
+               return 0;
+
+       if (txn->rsp.flags & HTTP_MSGF_VER_11)
+               smp->data.str.str = "HTTP/1.1";
+       else
+               smp->data.str.str = "HTTP/1.0";
+
+       smp->data.str.len = 8;
+       smp->type  = SMP_T_STR;
+       smp->flags = SMP_F_CONST;
+       return 1;
+
+}
+
 
 /* Iterate over all cookies present in a message. The context is stored in
  * smp->ctx.a[0] for the in-header position, smp->ctx.a[1] for the
@@ -10771,12 +10819,16 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
        { "base32",          smp_fetch_base32,         0,                NULL,    SMP_T_UINT, SMP_USE_HRQHV },
        { "base32+src",      smp_fetch_base32_src,     0,                NULL,    SMP_T_BIN,  SMP_USE_HRQHV },
 
-       { "capture.req.uri",    smp_fetch_capture_req_uri,    0,          NULL,    SMP_T_STR, SMP_USE_HRQHP },
-       { "capture.req.method", smp_fetch_capture_req_method, 0,          NULL,    SMP_T_STR, SMP_USE_HRQHP },
-
        /* capture are allocated and are permanent in the session */
        { "capture.req.hdr", smp_fetch_capture_header_req, ARG1(1, UINT), NULL,   SMP_T_STR,  SMP_USE_HRQHP },
+
+       /* retrieve these captures from the HTTP logs */
+       { "capture.req.method", smp_fetch_capture_req_method, 0,          NULL,   SMP_T_STR,  SMP_USE_HRQHP },
+       { "capture.req.uri",    smp_fetch_capture_req_uri,    0,          NULL,   SMP_T_STR,  SMP_USE_HRQHP },
+       { "capture.req.ver",    smp_fetch_capture_req_ver,    0,          NULL,   SMP_T_STR,  SMP_USE_HRQHP },
+
        { "capture.res.hdr", smp_fetch_capture_header_res, ARG1(1, UINT), NULL,   SMP_T_STR,  SMP_USE_HRSHP },
+       { "capture.res.ver", smp_fetch_capture_res_ver,       0,          NULL,   SMP_T_STR,  SMP_USE_HRQHP },
 
        /* cookie is valid in both directions (eg: for "stick ...") but cook*
         * are only here to match the ACL's name, are request-only and are used