⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_headers.html

📁 这个是我在web培训时老师提供的手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="Apache, 中文, 手册, 中文版, 中文手册, 中文版手册, 参考手册, 中文参考手册, 金步国" />
<meta name="description" content="Apache 2.2 中文版参考手册" />
<meta name="author" content="金步国" />
<link href="../style/css/manual-zip.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-zip-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
<title>mod_headers - Apache 2.2 中文版参考手册</title>
</head>
<body><div id="page-header">
<p class="menu"><a href="../mod/index.html">模块索引</a> | <a href="../mod/directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p><p class="apache">Apache HTTP Server 版本2.2</p><img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="./index.html"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
<div id="path"><a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">文档</a> &gt; <a href="../index.html">版本2.2</a> &gt; <a href="./index.html">模块</a></div>

<div id="translation-info">   <a href="../translator_announcement.html#thanks">致谢</a> | <a href="../translator_announcement.html#announcement">译者声明</a> | 本篇译者:<a href="mailto:&#099;sfr&#0097;nk&#0064;&#099;itiz&#046;n&#0101;t">金步国</a> | 本篇译稿最后更新:2006年1月25日 | <a href="../translator_announcement.html#last_new">获取最新版本</a></div>
<div id="page-content"><div id="preamble"><h1>Apache模块 mod_headers</h1>

<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="module">
<tr><th><a href="module-dict.html#Description">说明</a></th><td>允许通过配置文件控制任意的HTTP请求和应答头信息</td></tr>
<tr><th><a href="module-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="module-dict.html#ModuleIdentifier">模块名</a></th><td>headers_module</td></tr>
<tr><th><a href="module-dict.html#SourceFile">源文件</a></th><td>mod_headers.c</td></tr>
<tr><th><a href="module-dict.html#Compatibility">兼容性</a></th><td><code class="directive"><a href="#requestheader">RequestHeader</a></code>仅在 Apache 2.0 中有效</td></tr>
</table>
<h3>概述</h3>

    <p>这个模块提供了一些指令用于控制和修改HTTP请求头和应答头。这些头可以被合并、替换、删除。</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="order" id="order">处理顺序</a></h2>

    <p>由<code class="module"><a href="../mod/mod_headers.html">mod_headers</a></code>提供的指令几乎可以出现在配置文件的任何部分。并可以封装在<a href="../sections.html">配置段</a>中以限制其作用范围。</p>

    <p>指令的处理顺序很重要,它取决于指令本身在配置文件中的位置和所属<a href="../sections.html#mergin">配置段</a>在配置文件中的位置。下面的指令如果颠倒一下顺序将会导致完全不同的结果:</p>

    <div class="example"><p><code>
      RequestHeader append MirrorID "mirror 12"<br />
      RequestHeader unset MirrorID
    </code></p></div>

    <p>当前顺序下,<code>MirrorID</code>头不会被设置。若颠倒一下顺序,<code>MirrorID</code>头将被设为"mirror 12"。</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="early" id="early">前处理和后处理</a></h2>
    <p><code class="module"><a href="../mod/mod_headers.html">mod_headers</a></code>可以应用在请求被处理之前或之后。通常的模式是"后处理",也就是在请求处理完毕之后、发送应答之前设置应答头。[原文:when Request Headers are set immediately before running the content generator and Response Headers just as the response is sent down the wire.]在实际工作的服务器上应当始终使用"后处理"模式。</p>

    <p>"前处理"模式应当仅仅作为开发者使用的一种测试/调试辅助工具。可以在指令中使用<code>early</code>关键字启用"前处理"模式,此时将在处理请求之前设置请求头。这样就可以模拟各种不同的请求以协助调试。</p>

    <p>由于"前处理"模式的指令在将URL映射到文件系统之前就生效了,不能依赖于所请求的路径。所以"前处理"模式的指令只能用在主服务器和虚拟主机部分的配置中,而不能用于<code>&lt;Directory&gt;</code>或<code>&lt;Location&gt;</code>配置段中。</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="examples" id="examples">示例</a></h2>

    <ol>
      <li>将所有以"TS"开头的请求头复制到应答头中:
        <div class="example"><p><code>
          Header echo ^TS
        </code></p></div>
      </li>

      <li>在应答中添加一个<code>MyHeader</code>头来包含服务端接受到请求的时间戳和经过多少时间以后才完成对该请求的处理并作出应答。这个头可以让客户端知道瓶颈位于服务端还是位于服务端和客户端之间的线路。
        <div class="example"><p><code>
          Header add MyHeader "%D %t"
        </code></p></div>

        <p>上面的设置将会添加如下应答头内容:</p>

        <div class="example"><p><code>
          MyHeader: D=3775428 t=991424704447256
        </code></p></div>
      </li>

      <li>向Joe问好(Hello):
        <div class="example"><p><code>
          Header add MyHeader "Hello Joe. It took %D microseconds \<br />
          for Apache to serve this request."
        </code></p></div>

        <p>上面的设置将会添加如下应答头内容:</p>

        <div class="example"><p><code>
          MyHeader: Hello Joe. It took D=3775428 microseconds for Apache to serve this request.
        </code></p></div>
      </li>

      <li>当且仅当"MyRequestHeader"出现在请求头中的时候才在应答中发送"<code>MyHeader</code>"头。这个对根据特定的客户端构造特定的应答头很有用。注意,下面的例子需要<code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>模块的支持。
        <div class="example"><p><code>
          SetEnvIf MyRequestHeader value HAVE_MyRequestHeader<br />
          Header add MyHeader "%D %t mytext" env=HAVE_MyRequestHeader<br />
       </code></p></div>

       <p>如果请求中出现"<code>MyRequestHeader: value</code>"头,应答中将会包含下面的头:</p>

       <div class="example"><p><code>
         MyHeader: D=3775428 t=991424704447256 mytext
       </code></p></div>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -