That only returns the first result.
I went back to your previous test because I noticed something odd.
Here's the header portion of the message:
\nHTTP request header Accept: application/json\nHTTP request header Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\nHTTP request header User-Agent: Ruby\nHTTP request header Connection: close\nHTTP request header Host: myserver.com\n
When I used:
%{HTTP_REQUEST_HEADER:request_header}\n%{HTTP_REQUEST_HEADER:request_header}
I would get the Connection: close
and Host: myserver.com
headers, which are the last two headers. But anything returning a single result would return Accept: application/json
I went back and looked at my regex for the header directive and realized it was wrong:
%{WORD}
Doesn't accept hyphens. I redefined it:
HEADER [A-Za-z0-9_-]*
RESPONSE_VALUE [^\n]*
HTTP_REQUEST_HEADER HTTP request header *%{HEADER:header_directive}: %{RESPONSE_VALUE:header_value}
This time your previous example returned Accept: application/json
and Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
, which are the first two headers.
I went back excitedly to you most current example
%{HTTP_REQUEST_HEADER:request_header}(\n%{HTTP_REQUEST_HEADER:request_header})*
and now I get the first and the last: Accept: application/json
and Host: myserver.com
Just to keep testing, I brute-forced this particular request:
%{HTTP_REQUEST_HEADER:request_header}\n%{HTTP_REQUEST_HEADER:request_header}\n%{HTTP_REQUEST_HEADER:request_header}\n%{HTTP_REQUEST_HEADER:request_header}\n%{HTTP_REQUEST_HEADER:request_header}
and I successfully get all 5 headers: Accept: application/json
, Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
, User-Agent: Ruby
, Connection: close
, Host: myserver.com
That verifies that the %{HTTP_REQUEST_HEADER:request_header}
is successfully capturing the elements of the header. There is something about combining it with \n
and *
that is not working. I tried putting the \n
in the regex, but that breaks everything.