-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprotocol.txt
101 lines (72 loc) · 3.52 KB
/
protocol.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
SCGI: A Simple Common Gateway Interface alternative
Neil Schemenauer <[email protected]>
2008-06-23
1. Introduction
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.
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.
2. Protocol
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.
3. Request Format
A request consists of a number of headers and a body. The format of
the headers is:
headers ::= header*
header ::= name NUL value NUL
name ::= notnull+
value ::= notnull*
notnull ::= <01> | <02> | <03> | ... | <ff>
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.
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.
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.
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:,".
[len]":"[string]"," is called a netstring. [string] is called the
interpretation of the netstring.
5. Example
The web server (a SCGI client) opens a connection and sends the
concatenation of the following strings:
"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:
"Status: 200 OK" <0d 0a>
"Content-Type: text/plain" <0d 0a>
"" <0d 0a>
"42"
The SCGI server closes the connection.
6. Copyright
This document has been placed in the public domain.
/* vim: set ai tw=74 et sw=4 sts=4: */