SCGI: A Simple Common Gateway Interface alternative Neil Schemenauer 2008-06-23 1. Introduction 1. イントロダクション The SCGI protocol is a replacement for the Common Gateway Interface (CGI) protocol. It is a standard for applications to interface with HTTP servers. It is similar to FastCGI but is designed to be easier to implement. SCGIプロトコルは、Common Gateway Interface (CGI) プロトコルの代替です。 これは、HTTPサーバとのインターフェースを持つアプリケーションに関する規 格です。これは、FastCGIと類似していますが、より簡単に実装できるよう設計 されています。 In this document, a string of 8-bit bytes may be written in two different forms: as a series of hexadecimal numbers between angle brackets, or as a sequence of ASCII characters between double quotes. For example, <68 65 6c 6c 6f 20 77 6f 72 6c 64 21> is a string of length 12; it is the same as the string "hello world!". Note that these notations are part of this document, not part of the protocol. この文書では、8ビットのバイト列は、2つの異なる形式で表現されます: ひと つは山カッコでくくられた16進数列、もうひとつは、ダブルクォートでくくら れたアスキー文字列です。例えば、<68 65 6c 6c 6f 20 77 6f 72 6c 64 21>は 12の長さを持つ文字列です; これは文字列"hello world!" と同じです。なお、 これらの表記法はこの文書の一部であり、プロトコルの一部ではないことにご 注意ください。 2. Protocol 2. プロトコル The client connects to a SCGI server over a reliable stream protocol allowing transmission of 8-bit bytes. The client begins by sending a request. See section 3 for the format of the request. When the SCGI server sees the end of the request it sends back a response and closes the connection. The format of the response is not specified by this protocol. クライアントは、8ビットのバイト列を伝送可能な信頼できるストリームプロト コルを用いて、SCGIサーバーに接続します。クライアントは、リクエストを送 ることから始めます。リクエストフォーマットについては、第3節を参照してく ださい。SCGIサーバーはリクエストの終了を認識すると、レスポンスを返して 接続を閉じます。レスポンスのフォーマットは、このプロトコルでは定義され ません。 3. Request Format 3. リクエストフォーマット A request consists of a number of headers and a body. The format of the headers is: リクエストは、複数のヘッダと1つのボディからなります。ヘッダのフォーマッ トは、以下の通りです: headers ::= header* header ::= name NUL value NUL name ::= notnull+ value ::= notnull* notnull ::= <01> | <02> | <03> | ... | NUL = <00> Duplicate names are not allowed in the headers. The first header must have the name "CONTENT_LENGTH" and a value that is a nonempty sequence of ASCII digits giving the of the body length in decimal. The "CONTENT_LENGTH" header must always be present, even if its value is "0". There must also always be a header with the name "SCGI" and a value of "1". In order to facilitate the transition from CGI, standard CGI environment variables should be provided as SCGI headers. ヘッダ部では、名前が重複してはいけません。最初のヘッダは、名前が "CONTENT_LENGTH"で、値がボディの長さを示す空でないASCIIの十進数字列です。 "CONTENT_LENGTH"ヘッダは、たとえその値が"0"であっても常に存在しなければ なりません。また、名前が"SCGI"、値が"1"であるヘッダも常に存在しなければ なりません。CGI からの移行を容易にするために、標準CGI環境変数は、SCGIヘッ ダとして提供されなければなりません。 The headers are sent encoded as a netstring. Netstring encoding is explained in section 4. The body is sent following the headers and its length is specified by the "CONTENT_LENGTH" header. ヘッダは、netstringにエンコードされて送信されます。netstring符号化は第 4節で説明します。ボディはヘッダに続けて送られます。その長さは "CONTENT_LENGTH"ヘッダによって指定されます。 4. Netstrings 4. Netstrings Any string of 8-bit bytes may be encoded as [len]":"[string]",". Here [string] is the string and [len] is a nonempty sequence of ASCII digits giving the length of [string] in decimal. The ASCII digits are <30> for 0, <31> for 1, and so on up through <39> for 9. Extra zeros at the front of [len] are prohibited: [len] begins with <30> exactly when [string] is empty. 8ビットのあらゆる文字列は、[len]":"[string]","にエンコードされます。こ こで、[string]は文字列、[len]は[string]の長さを示す空でないASCIIの十進 数字列です。ASCII数字は0が<30>、1が<31>と続き、9が<39>となります。 [len]の前に0を追加することは禁止です。すなわち、[len]が<30>から始まるの は[string]が空のときだけです。 For example, the string "hello world!" is encoded as <31 32 3a 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 2c>, i.e., "12:hello world!,". The empty string is encoded as "0:,". たとえば、文字列"hello world!"は、<31 32 3a 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 2c>、すなわち"12:hello world!,"にエンコードされます。空の文字 列は"0:,"にエンコードされます。 [len]":"[string]"," is called a netstring. [string] is called the interpretation of the netstring. [len]":"[string]","はnetstringと呼ばれています。[string]はnetstringの解 釈と呼ばれています。 5. Example 5. 例 The web server (a SCGI client) opens a connection and sends the concatenation of the following strings: ウェブサーバ(SCGIクライアント)は、(訳注:SCGIサーバに)接続し、以下の文字 列を結合したものを送ります: "70:" "CONTENT_LENGTH" <00> "27" <00> "SCGI" <00> "1" <00> "REQUEST_METHOD" <00> "POST" <00> "REQUEST_URI" <00> "/deepthought" <00> "," "What is the answer to life?" The SCGI server sends the following response: SCGIサーバーは以下のレスポンスを返します: "Status: 200 OK" <0d 0a> "Content-Type: text/plain" <0d 0a> "" <0d 0a> "42" The SCGI server closes the connection. SCGIサーバーは接続をクローズします。 6. Copyright 6. 著作権 This document has been placed in the public domain. この文書はパブリックドメインです。 /* vim: set ai tw=74 et sw=4 sts=4: */