Skip to content

Instantly share code, notes, and snippets.

@jatrost
Created February 8, 2020 01:21
Show Gist options
  • Save jatrost/9dc1e877fe3377d68986d0493cad7b6e to your computer and use it in GitHub Desktop.
Save jatrost/9dc1e877fe3377d68986d0493cad7b6e to your computer and use it in GitHub Desktop.
##! Extract and include the header names used for each request in the HTTP
##! logging stream. The headers in the logging stream will be stored in the
##! same order which they were seen on the wire.
@load base/protocols/http/main
module HTTP;
export {
redef record Info += {
## The vector of HTTP header names sent by the client. No
## header values are included here, just the header names.
client_headers: vector of string &log &optional;
## The vector of HTTP header names sent by the server. No
## header values are included here, just the header names.
server_headers: vector of string &log &optional;
};
## A boolean value to determine if client header names are to be logged.
const log_client_headers = T &redef;
## A boolean value to determine if server header names are to be logged.
const log_server_headers = F &redef;
}
event http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3
{
if ( ! c?$http )
return;
if ( is_orig )
{
if ( log_client_headers )
{
if ( ! c$http?$client_headers )
c$http$client_headers = vector();
c$http$client_headers[|c$http$client_headers|] = name + ": " + value;
}
}
else
{
if ( log_server_headers )
{
if ( ! c$http?$server_headers )
c$http$server_headers = vector();
c$http$server_headers[|c$http$server_headers|] = name +": "+value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment