Simple Common Gateway Interface
This article needs additional citations for verification. (October 2017) |
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 implement and crucially, permits CGI operations where the CGI operation has significant latency[clarification needed] (e.g. contacting an external database).
Specification
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. 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.[note 1]
Request format
A SCGI request is the concatenation of netstring-encoded headers and a body. A SCGI response is a normal HTTP response.
Each header consists of a name-value pair, where both the name and the value are null-terminated strings(C-strings). The value can be an empty string, in which case the terminating null still remains. Neither name nor value can contain any embedded null bytes. These considerations are standard for C-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 netstring-encoded. The body, if any, is then appended.
Duplicate names are not allowed in the headers. The first header must have the name "CONTENT_LENGTH" and a value that is the length of the body 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". Standard CGI environment variables should be provided in SCGI headers for compatibility with older CGI programs. The body is sent following the headers and its length is specified by the "CONTENT_LENGTH" header.
Example
The web server (a SCGI client) opens a connection and sends the concatenation of the following strings to the service process(a SCGI server):
"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 back to the web server:
"Status: 200 OK" <0d 0a> "Content-Type: text/plain" <0d 0a> "" <0d 0a> "42"
The SCGI server closes the connection.
Example
The web server (an SCGI client) opens a connection and sends the concatenation of the following strings:
"70:" "CONTENT_LENGTH" <00> "56" <00> "SCGI" <00> "1" <00> "REQUEST_METHOD" <00> "POST" <00> "REQUEST_URI" <00> "/deepthought" <00> "," "What is the answer to life, the Universe and everything?"
The web application (SCGI server) sends the following response:
"Status: 200 OK" <0d 0a> "Content-Type: text/plain" <0d 0a> "" <0d 0a> "42"
The SCGI server then closes the connection.
Web servers that implement SCGI
![]() | This section needs expansion. You can help by adding to it. (August 2008) |
- Apache HTTP Server
- Cherokee
- Lighttpd
- Microsoft Internet Information Services with ISAPI SCGI extension
- nginx
Language bindings for the SCGI API
![]() | This section needs expansion. You can help by adding to it. (October 2008) |
- Cobra
- Haskell
- Java, with SCGI connector
- Lisp
- Perl, with the SCGI Package
- PHP
- Python
- Racket, with the scgi: Web Server HTTP SCGI and CGI
- Ruby
- Scheme
- Tcl
- Nim
Notes
- 1.^ The specification document was placed in the public domain by Neil Schemenauer on 12 January 2006.
See also
- Rack - Ruby web server interface
- PSGI - Perl Web Server Gateway Interface
- WSGI - Web Server Gateway Interface
External links
![]() | This article's use of external links may not follow Wikipedia's policies or guidelines. (January 2018) |
- SCGI specification
- netstrings specification
- Ether - Ada SCGI library
- Original Ada SCGI interface
- Apache SCGI modules and Python SCGI interface
- Perl SCGI interface
- Haskell SCGI package
- Nginx SCGI Module
- Tcl SCGI module
- IIS SCGI extension
- Guile Scheme library