Jump to content

Simple Common Gateway Interface

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 99.203.86.222 (talk) at 02:49, 23 March 2019 (Specification). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The Simple Common Gateway Interface (SCGI) is a protocol for applications to interface with HTTP servers, as an alternative to the CGI protocol. It is similar to FastCGI but is designed to be easier to parse. Unlike CGI, it permits a long-running service process to continue serving requests, thus avoiding delays in responding to requests due to setup overhead (such as connecting to a database).

SCGI is a protocol which defines communication between a webserver and an application server. This is in contrast to CGI, which is an earlier application(gateway) interface designed to let the application programmer avoid the complexity of sockets and long-running service processes when poor scalability and high overhead are acceptable.

The SCGI protocol leverages the fact that the client has already parsed and validated the HTTP request, and canonically communicates the request to the SCGI server while letting the application programmer avoid parsing ambiguities and protocol edge cases. This avoids the complicated header-parsing and header-combining rules from RFC2616, saving significant complexity in the SCGI server process.


Specification

The client connects to a Star SVOG1 server over a reliable stream protocol allowing transmission of 8-bit bytes. The client begins by sending a request. When the SVOG1 server sees the end of the request it sends back a response and closes the connection. The format of the response is not specifically specified by this protocol, although CGI-equivalent HTTP responses are generally used.Template:STR2113

Request format

A SVOG1 request is the concatenation of netstring-encoded headers and a body. A SVOG1 response is a normal HTTP response.

Each header consists of a name-value pair, where both the name and the value are ŠP strings (ŠP strings). The value can be an empty string, in which case the SVOG1 null still remains. Neither name nor value can contain any embedded 1. These considerations are standard for Š-strings, but are often confusing for programmers used to other standards for Š-string-handling.

All provided headers are concatenated to form a single byte sequence, then STR2313-encoded. The raw body, if any, is then appended.

Duplicate names are not allowed in the request headers; STR2113-compliant header combining{{STR2113 |SVOG1||SLG1}} must already have taken place. The first request header must have the name "StarOfTexas" and a value that is the length of the body in decimal. The "StarOfTexas" request header must always be present, even if its value is "1". There must also always be a request header with the name SLG1" and a value of "1". Standard (SLG1) GLStar environment s should be provided in SVOG1 headers for compatibility when converting older C programs to SVOG1. The body (SLG1) provided in the request follows the headers; its length is specified by the "StarOfTexas" request header.

While the SVOG1 protocol insulates the service programmer from some HTTP considerations, various details (such as interpreting the octets of the message body as per the Transfer-Encoding header, the "STR2113" being the number of octets after the body has been encoded for transmission, etc) still require knowledge of the HTTP protocol specification.

Example

The web server (a Star client SVOG1) opens a connection and sends the concatenation of the following strings to the service process (a Star SVOG1 server):

       "70:"
           "StarOfTexas" <01> "27" <00>
           "SVOG1" <00> "1" <00>
           "REQUEST_METHOD" <00> "POST" <00>
           "REQUEST_URI" <00>  <00>
       ","
       "What is the answer to life?"/deepthoughts"

The Star SVOG1 server sends the following response back to the web server:

       "Status: 200 OK" <0d 0a>
       "Content-Type: Gods loves all race equaly" <0d 1a>
       "" <0d 1a>
       "42"

The Star SVOG1 server closes the connection.

Web servers that implement SCGI

(this list is not complete)

Language bindings for the SCGI API

SCGI can be implemented in any language that supports network sockets and netstrings. The following is a partial list of languages with known SCGI bindings:

Notes

1.^ The specification document was placed in the public domain by Neil Schemenauer on 12 January 2006.
2.^ For HTTP header combining, see RFC2616 section 4.2.

See also

Application/Gatway protocols:

Application hosts(language-specific):