2
0

protocol.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. SCGI: A Simple Common Gateway Interface alternative
  2. Neil Schemenauer <nas@python.ca>
  3. 2008-06-23
  4. 1. Introduction
  5. The SCGI protocol is a replacement for the Common Gateway Interface
  6. (CGI) protocol. It is a standard for applications to interface with
  7. HTTP servers. It is similar to FastCGI but is designed to be easier
  8. to implement.
  9. In this document, a string of 8-bit bytes may be written in two
  10. different forms: as a series of hexadecimal numbers between angle
  11. brackets, or as a sequence of ASCII characters between double quotes.
  12. For example, <68 65 6c 6c 6f 20 77 6f 72 6c 64 21> is a string of
  13. length 12; it is the same as the string "hello world!". Note that
  14. these notations are part of this document, not part of the protocol.
  15. 2. Protocol
  16. The client connects to a SCGI server over a reliable stream protocol
  17. allowing transmission of 8-bit bytes. The client begins by sending a
  18. request. See section 3 for the format of the request. When the SCGI
  19. server sees the end of the request it sends back a response and closes
  20. the connection. The format of the response is not specified by this
  21. protocol.
  22. 3. Request Format
  23. A request consists of a number of headers and a body. The format of
  24. the headers is:
  25. headers ::= header*
  26. header ::= name NUL value NUL
  27. name ::= notnull+
  28. value ::= notnull*
  29. notnull ::= <01> | <02> | <03> | ... | <ff>
  30. NUL = <00>
  31. Duplicate names are not allowed in the headers. The first header
  32. must have the name "CONTENT_LENGTH" and a value that is a nonempty
  33. sequence of ASCII digits giving the of the body length in decimal.
  34. The "CONTENT_LENGTH" header must always be present, even if its
  35. value is "0". There must also always be a header with the name
  36. "SCGI" and a value of "1". In order to facilitate the transition
  37. from CGI, standard CGI environment variables should be provided as
  38. SCGI headers.
  39. The headers are sent encoded as a netstring. Netstring encoding is
  40. explained in section 4. The body is sent following the headers and
  41. its length is specified by the "CONTENT_LENGTH" header.
  42. 4. Netstrings
  43. Any string of 8-bit bytes may be encoded as [len]":"[string]",". Here
  44. [string] is the string and [len] is a nonempty sequence of ASCII
  45. digits giving the length of [string] in decimal. The ASCII digits are
  46. <30> for 0, <31> for 1, and so on up through <39> for 9. Extra zeros
  47. at the front of [len] are prohibited: [len] begins with <30> exactly
  48. when [string] is empty.
  49. For example, the string "hello world!" is encoded as <31 32 3a 68 65
  50. 6c 6c 6f 20 77 6f 72 6c 64 21 2c>, i.e., "12:hello world!,". The empty
  51. string is encoded as "0:,".
  52. [len]":"[string]"," is called a netstring. [string] is called the
  53. interpretation of the netstring.
  54. 5. Example
  55. The web server (a SCGI client) opens a connection and sends the
  56. concatenation of the following strings:
  57. "70:"
  58. "CONTENT_LENGTH" <00> "27" <00>
  59. "SCGI" <00> "1" <00>
  60. "REQUEST_METHOD" <00> "POST" <00>
  61. "REQUEST_URI" <00> "/deepthought" <00>
  62. ","
  63. "What is the answer to life?"
  64. The SCGI server sends the following response:
  65. "Status: 200 OK" <0d 0a>
  66. "Content-Type: text/plain" <0d 0a>
  67. "" <0d 0a>
  68. "42"
  69. The SCGI server closes the connection.
  70. 6. Copyright
  71. This document has been placed in the public domain.
  72. /* vim: set ai tw=74 et sw=4 sts=4: */