#?SuikaWiki/0.9 [5] [DFN[[CODE(CGI)[HTTP_[VAR[*]]]]]] は、[[クライアント]]から送られてきた[[要求メッセージ]]に含まれていた[[頭欄]]の[[本体]]を[[鯖]]が [[CGIスクリプト]]に提供するため [[CGI]] [[メタ変数]]です群。 [VAR[*]] の部分は、欄名をすべて大文字にし、 [CODE(HTTP)[-]] を [CODE(CGI)[_]] に置換えたものとなります。 たとえば、 [CODE(HTTP)[[[Accept]]:]] 欄に対応するメタ変数は [CODE(CGI)[[[HTTP_ACCEPT]]]] で、 [CODE(HTTP)[[[If-Modified-Since]]:]] 欄に対応するメタ変数は [CODE(CGI)[HTTP_IF_MODIFIED_SINCE]] です。 [[#comment]] * 仕様書から ** [NCSA] での説明 [6] >In addition to these, the header lines received from the client, if any, are placed into the environment with the prefix HTTP_ followed by the header name. Any - characters in the header name are changed to _ characters. The server may exclude any headers which it has already processed, such as Authorization, Content-type, and Content-length. If necessary, the server may choose to exclude any or all of these headers if including them would exceed any system environment limits. これら [INS[(訳注: 他の CGI メタ変数群)]] に加えて、クライアントから受け取った[[頭行]]があれば、 これが接頭辞 [CODE(CGI)[HTTP_]] で始まって頭名が続く環境[INS[変数]]に入れられます。 頭名中の [CODE(HTTP)[[[-]]]] はすべて [CODE(CGI)[[[_]]]] に変更します。 サーバーは既に処理した頭、 例えば [CODE(HTTP)[Authorization]], [CODE(HTTP)[Content-type]], [CODE(HTTP)[Content-length]] は除いても構いません。 必要なら、サーバーはこうした頭の一部又は全部を含めるとシステムの環境制限を越える時には除いても構いません。 **CGI/1.1 draft #3 6.1.5. Protocol-Specific Metavariables (プロトコル規定メタ変数) [7] > These metavariables are specific to the protocol via which the request is made. Interpretation of these variables depends on the value of the SERVER_PROTOCOL metavariable (see section 6.1.17). このメタ変数群は、要求が送られてきたプロトコルにより決まります。 この変数群の解釈は [[SERVER_PROTOCOL]] メタ変数 (第6.1.17節を参照) の値によります。 [8] >Metavariables with names beginning with "HTTP_" contain values from the request header, if the scheme used was HTTP. Each HTTP header field name is converted to upper case, has all occurrences of "-" replaced with "_", and has "HTTP_" prepended to form the metavariable name. Similar transformations are applied for other protocols. The header data MAY be presented as sent by the client, or MAY be rewritten in ways which do not change its semantics. If multiple header fields with the same field-name are received then the server MUST rewrite them as though they had been received as a single header field having the same semantics before being represented in a metavariable. Similarly, a header field that is received on more than one line MUST be merged into a single line. The server MUST, if necessary, change the representation of the data (for example, the character set) to be appropriate for a CGI metavariable. 「HTTP_」で始まる名前のメタ変数は、使われた方式が HTTP である場合に、 要求頭から取られます。各 HTTP 頭領域名を大文字に変換して、 「-」が含まれれば全て「_」に置き換えて、「HTTP_」を頭につけたのが メタ変数名になります。同様の変換を他のプロトコルについても行います。 頭データはクライアントから送られてきたものを使っても'''良い'''ですし、 意味を変えない範囲で書き換えても'''構いません'''。同じ領域名で 複数の頭領域を受け取った場合、サーバーはメタ変数にする前に、 同じ意味を持つ単一頭領域を受け取ったものとして書き換え'''なければなりません'''。 同様に、複数行で受け取った頭領域は単一行にくっつけなければ '''なりません'''。サーバーは、必要があれば、データの表現 (例えば文字集合) を CGI メタ変数に適切な形に変えなければ '''なりません'''。 [9] >Servers are not required to create metavariables for all the request header fields that they receive. In particular, they MAY decline to make available any header fields carrying authentication information, such as "Authorization", or which are available to the script via other metavariables, such as "Content-Length" and "Content-Type". サーバーは受け取った頭領域全てについてメタ変数を作る必要はありません。 特に、「Authorization」(認証)のような認証情報を伝達する頭領域や、 他のメタ変数でスクリプトに伝えられる「Content-Length」(内容長) や「Content-Type」(内容型)のような頭領域を利用出来なくしても '''構いません'''。 ** I-D のライセンス [[RFCのライセンス]]を参照。 * 提供されないことが多い頭欄 [11] >>9 に規定されているように、鯖は CGI スクリプトに要求メッセージのすべての頭欄を [CODE(CGI)[HTTP_[VAR[*]]]] メタ変数を通じて提供する必要はありません。 多くの実装では、次の頭欄は提供されません。 ,HTTP 頭欄 ,代替メタ変数 ,[CODE(HTTP)[[[Authorization]]]],[CODE(CGI)[[[AUTH_[VAR[*]]]]]] ,[CODE(HTTP)[[[Content-Length]]]],[CODE(CGI)[[[CONTENT_LENGTH]]]] ,[CODE(HTTP)[[[Content-Type]]]],[CODE(CGI)[[[CONTENT_TYPE]]]] [3] >>9 つまり、 CGI 的には [CODE(CGI)[HTTP_AUTHORIZATION]] と かが提供されていて''も''問題がないということです。 [4] >>3 でも [[Apache]] は提供してくれません。 [10] CGI メタ変数はほとんどの環境では[[環境変数]]として実装されていますが、 環境変数が安全でない環境も少なくありません。 その鯖の任意の利用者が環境変数の値を見ることができるかもしれません。 CGI で昔から認証系の頭欄が提供されないことになっているのはそのような事情があります。 [[#comment]] * メモ - [1] 方式 (scheme) が [[https:]] だったら ''HTTPS_[VAR[*]]'' になるんでしょうか。そんなの見たこと無いなあ。 - [2] >>1 そんなことはないです。 HTTP over SSL でも [CODE(CGI)[HTTP_[VAR[*]]]] になります。