简单通用网关接口 (,简称 SCGI) 是一种让应用程序与 HTTP 服务器交互的协议,作为 CGI 协议的替代。它类似于 FastCGI 但它被设计地更容易实现,且最重要的是,允许有很大延迟的 CGI 操作(如联系外部数据库)。
规范
客户端通过一个可靠的流流协议连接到一个 SCGI 服务器,进行 8 比特字节的传输。客户端首先发送请求,当 SCGI 服务器看到请求结束时,它会将回应发送回来并关闭连接。
请求格式
请求包含几个头部和正文。头部的格式是:
headers ::= header*
header ::= name NUL value NUL
name ::= notnull+
value ::= notnull*
notnull ::= | | | … |
NUL =
头部中不允许出现重复的名称。第一个头部的名称必须是 "CONTENT_LENGTH" 且值为正文的十进制长度。 "CONTENT_LENGTH" 头必须始终存在,即使它的值为 "0" 。此外还必须有一个头部的名称为 "SCGI" 且值为 "1"。为了方便从 CGI 过渡,标准的 CGI 环境变量也应该被作为 SCGI 头部提供。
头部会被编码为 netstring ,然后发送到服务器应用程序。正文将在头部后发送,它的长度由 "CONTENT_LENGTH" 头部指定。
示例
网页服务器(SCGI 客户端)打开连接并发送以下字符串拼接起来的数据:
"70:"
"CONTENT_LENGTH" "56"
"SCGI" "1"
"REQUEST_METHOD" "POST"
"REQUEST_URI" "/deepthought"
","
"What is the answer to life, the Universe and everything?"
网页应用程序(SCGI 服务器)发送以下回应:
"Status: 200 OK"
"Content-Type: text/plain"
""
"42"
然后 SCGI 服务器关闭连接。
实现 SCGI 的网页服务器
- Apache HTTP Server
- Cherokee
- Lighttpd
- [http://www.mathopd.org Mathopd] - 通过非官方补丁
- 带 [http://isapi-scgi.sourceforge.net/ ISAPI SCGI 扩展] 的微软網際網路資訊服務
- Nginx
- Avuna HTTPD
SCGI API 的语言绑定
- Cobra
- Haskell
- Java,通过 [http://gist.github.com/38425 SCGI connector]
- Lisp
- Perl,通过 [https://metacpan.org/release/SCGI SCGI 包]
- PHP
- Python
- Racket,通过 [https://www.neilvandyke.org/racket/scgi/ scgi: Web Server HTTP SCGI and CGI]
- Ruby
- Scheme
- Tcl
- Nim
注释
: 1.规范文档在 2006 年 1 月 12 日的时候被发布至公有领域。
参见
- Rack - Ruby 网页服务器接口
- PSGI - Perl 网页服务器接口
- WSGI
外部链接
- [http://www.python.ca/scgi/protocol.txt SCGI specification]
- [https://cr.yp.to/proto/netstrings.txt netstrings specification]
- [https://github.com/Lucretia/ether Ether - Ada SCGI library]
- [https://github.com/jesselang/Solid-Web Original Ada SCGI interface]
- [https://python.ca/scgi/ Apache SCGI modules and Python SCGI interface]
- [https://metacpan.org/release/SCGI Perl SCGI interface]
- [https://hackage.haskell.org/cgi-bin/hackage-scripts/package/scgi Haskell SCGI package]
- [https://nginx.org/en/docs/http/ngx_http_scgi_module.html Nginx SCGI Module]
- Tcl SCGI module
- [http://isapi-scgi.sourceforge.net IIS SCGI extension]
- [https://web.archive.org/web/20140726231034/http://sph.io/content/8eb Guile Scheme library]
评论 (0)