1.. Licensed to the Apache Software Foundation (ASF) under one 2 or more contributor license agreements. See the NOTICE file 3 distributed with this work for additional information 4 regarding copyright ownership. The ASF licenses this file 5 to you under the Apache License, Version 2.0 (the 6 "License"); you may not use this file except in compliance 7 with the License. You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, 12 software distributed under the License is distributed on an 13 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 KIND, either express or implied. See the License for the 15 specific language governing permissions and limitations 16 under the License. 17 18.. include:: ../../../common.defs 19 20.. _developer-plugins-http-headers-functions: 21 22Header Functions 23**************** 24 25The Traffic Server API HTTP header functions enable you to work with 26HTTP header data stored in marshal buffers. 27 28The HTTP header data structure is a parsed version of the HTTP header 29defined in the HTTP protocol specification. An HTTP header is composed 30of a request or response line followed by zero or more MIME fields. In 31fact, an HTTP header is a subclass of a MIME header; all of the MIME 32header routines operate on HTTP headers. 33 34An HTTP **request line** is composed of a method, a URL, and version. A 35**response line** is composed of a version, status code, and reason 36phrase. See `About HTTP Headers <../http-headers#AboutHTTPHeaders>`__ 37for additional details and examples. 38 39To facilitate fast comparisons and reduce storage size, Traffic Server 40defines several pre-allocated method names. These names correspond to 41the methods defined in the HTTP 1.1 specification 42 43``TS_HTTP_METHOD_CONNECT`` 44 "CONNECT" 45 46``TS_HTTP_METHOD_DELETE`` 47 "DELETE" 48 49``TS_HTTP_METHOD_GE`` 50 "GET" 51 52``TS_HTTP_METHOD_HEAD`` 53 "HEAD" 54 55``TS_HTTP_METHOD_OPTIONS`` 56 "OPTIONS" 57 58``TS_HTTP_METHOD_POST`` 59 "POST" 60 61``TS_HTTP_METHOD_PURGE`` 62 "PURGE" 63 64``TS_HTTP_METHOD_PUT`` 65 "PUT" 66 67``TS_HTTP_METHOD_TRACE`` 68 "TRACE" 69 70``TS_HTTP_METHOD_PUSH`` 71 "PUSH" 72 73Traffic Server also defines several common values that appear in HTTP 74headers. 75 76``TS_HTTP_VALUE_BYTES`` 77 "bytes" 78 79``TS_HTTP_VALUE_CHUNKED`` 80 "chunked" 81 82``TS_HTTP_VALUE_CLOSE`` 83 "close" 84 85``TS_HTTP_VALUE_COMPRESS`` 86 "compress" 87 88``TS_HTTP_VALUE_DEFLATE`` 89 "deflate" 90 91``TS_HTTP_VALUE_GZIP`` 92 "gzip" 93 94``TS_HTTP_VALUE_IDENTITY`` 95 "identity" 96 97``TS_HTTP_VALUE_KEEP_ALIVE`` 98 "keep-alive" 99 100``TS_HTTP_VALUE_MAX_AGE`` 101 "max-age" 102 103``TS_HTTP_VALUE_MAX_STALE`` 104 "max-stale" 105 106``TS_HTTP_VALUE_MIN_FRESH`` 107 "min-fresh" 108 109``TS_HTTP_VALUE_MUST_REVALIDATE`` 110 "must-revalidate" 111 112``TS_HTTP_VALUE_NONE`` 113 "none" 114 115``TS_HTTP_VALUE_NO_CACHE`` 116 "no-cache" 117 118``TS_HTTP_VALUE_NO_STORE`` 119 "no-store" 120 121``TS_HTTP_VALUE_NO_TRANSFORM`` 122 "no-transform" 123 124``TS_HTTP_VALUE_ONLY_IF_CACHED`` 125 "only-if-cached" 126 127``TS_HTTP_VALUE_PRIVATE`` 128 "private" 129 130``TS_HTTP_VALUE_PROXY_REVALIDATE`` 131 "proxy-revalidate" 132 133``TS_HTTP_VALUE_PUBLIC`` 134 "public" 135 136``TS_HTTP_VALUE_S_MAX_AGE`` 137 "s-maxage" 138 139The method names and header values above are defined in ``ts.h`` as 140``const char*`` strings. When Traffic Server sets a method or a header 141value, it checks to make sure that the new value is one of the known 142values. If it is, then it stores a pointer into a global table (instead 143of storing the known value in the marshal buffer). The method names and 144header values listed above are also pointers into this table. This 145allows simple pointer comparison of the value returned from 146``TSHttpMethodGet`` with one of the values listed above. It is also 147recommended that you use the above values when referring to one of the 148known schemes, since this removes the possibility of a spelling error. 149 150The **HTTP Header Functions** are listed below: 151 152- :c:func:`TSHttpHdrClone` 153- :c:func:`TSHttpHdrCopy` 154- :c:func:`TSHttpHdrCreate` 155- :c:func:`TSHttpHdrDestroy` 156- :c:func:`TSHttpHdrLengthGet` 157- :c:func:`TSHttpHdrMethodGet` 158- :c:func:`TSHttpHdrMethodSet` 159- :c:func:`TSHttpHdrPrint` 160- :c:func:`TSHttpHdrReasonGet` 161- :c:func:`TSHttpHdrReasonLookup` 162- :c:func:`TSHttpHdrReasonSet` 163- :c:func:`TSHttpHdrStatusGet` 164- :c:func:`TSHttpHdrStatusSet` 165- :c:func:`TSHttpHdrTypeGet` 166- :c:func:`TSHttpHdrTypeSet` 167- :c:func:`TSHttpHdrUrlGet` 168- :c:func:`TSHttpHdrUrlSet` 169- :c:func:`TSHttpHdrVersionGet` 170- :c:func:`TSHttpHdrVersionSet` 171- :c:func:`TSHttpParserClear` 172- :c:func:`TSHttpParserCreate` 173- :c:func:`TSHttpParserDestroy` 174- :c:func:`TSHttpHdrParseReq` 175- :c:func:`TSHttpHdrParseResp` 176 177