【问题标题】:Custom LogFormat - Log all headers自定义 LogFormat - 记录所有标题
【发布时间】:2011-09-20 12:21:37
【问题描述】:

一些移动网关正在将自定义标头传递到我的网站。这些标头以各种格式传递,有时是 x-msisdn,有时是 x-up-calling-line-id 等。如何记录以我的自定义日志格式传递的所有标头?

【问题讨论】:

  • 您不能仅使用 Apache 和 mod_log_config 来执行此操作。您可以使用 mod_security

标签: apache apache2


【解决方案1】:

通过 Apache HTTPD 我不确定如何记录 所有 标头 - 只知道如何记录您知道的一个标头。

使用标准 Apache httpd 模块 mod_log_config,您可以在 CustomLog 指令中指定以下选项。

%{Foobar}i Foobar 的内容:发送到服务器的请求中的标题行。其他模块(例如 mod_headers)所做的更改会影响这一点。

但是您可以在 jsp 中执行此操作(如果这是您偶然使用的)

<!-- method used to send request
<%= request.getMethod() %>

URI of the request
<%= request.getRequestURI() %>

  <%
     /*This method returns an enumeration of all the header names this 
       request contains.*/       
  java.util.Enumeration names = request.getHeaderNames();
  while (names.hasMoreElements()) {
     String hname = (String)names.nextElement();
  %>

     <%= hname %>
     <%= request.getHeader(hname) %>
  <%
  }
  %>
--!>

【讨论】:

    【解决方案2】:

    您也可以通过嗅探网络接口来执行此操作。

    Wireshark 有 tshark (apt-get install tshark) tshark 'tcp 端口 80 和 (((ip[2:2] - ((ip[0]&0xf)>2)) != 0)' -R 'http.request.method == "GET" || http.request.method == "HEAD"'

    (以上来自http://andy.wordpress.com/2008/07/10/sniffing-http/tshark 是 tethereal 的新名称)

    或使用类似https://github.com/caesar0301/http-sniffer

    【讨论】:

      猜你喜欢
      • 2011-05-03
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 2013-03-30
      • 2014-01-26
      相关资源
      最近更新 更多