Skip to content

Commit a12359e

Browse files
committed
Better documentation
1 parent 4e9511f commit a12359e

File tree

1 file changed

+85
-15
lines changed

1 file changed

+85
-15
lines changed

README.md

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ This module is a replacement for node's http module (server only). It can be use
1313

1414
The implementation is fully compliant with [FastCGI 1.0 Specification](http://www.fastcgi.com/drupal/node/6?q=node/22).
1515

16-
1716
Example
1817
-------
1918

@@ -31,19 +30,76 @@ fcgi.createServer(function(req, res) {
3130
}).listen();
3231
```
3332

34-
http module compatibility
35-
-------------------------
33+
Server constructor
34+
------------------
3635

37-
The API is almost compatible with http module from node v0.12 all the way to v6.2 (the current version).
36+
The `createServer` function takes four **optional** parameters:
3837

39-
Differences:
40-
- A FastCGI server will never emit `'checkContinue'` and `'connect'` events because `CONNECT` method and `Expect: 100-continue` headers should be handled by the front-end http server
41-
- The `'upgrade'` event is not currently implemented. Typically upgrade/websocket requests won't work with FastCGI applications because of input/output buffering.
42-
- `server.listen()` can be called without arguments (or with a callback as the only argument) to listen on the default FastCGI socket `{ fd: 0 }`.
43-
- `server.maxHeadersCount` is useless
44-
- `request.socket` is not a real socket. Read the next section for more information.
45-
- `request.trailers` will always be empty: CGI scripts never receive trailers
46-
- `response.writeContinue()` works as expected but should not be used. See first item
38+
- `responder`: callback for FastCGI responder requests (normal HTTP requests, listener for the `'request'` event).
39+
- `authorizer`: callback for FastCGI authorizer requests (listener for the `'authorize'` event)
40+
- `filter`: callback for FastCGI filter requests (listener for the `'filter'` event)
41+
- `config`: server configuration
42+
43+
`config` is an object with the following defaults:
44+
45+
```js
46+
{
47+
maxConns: 2000,
48+
maxReqs: 2000,
49+
multiplex: true,
50+
valueMap: {}
51+
}
52+
```
53+
54+
`maxConns` is the maximum number of connections accepted by the server. This limit is not enforced, it is only used to provide the FCGI_MAX_CONNS value when queried by a FCGI_GET_VALUES record.
55+
56+
`maxReqs` is the maximum number of total concurrent requests accepted by the server (over all connections). The limit is not enforced, but compliant clients should respect it, so do not set it too low. This setting is used to provide the FCGI_MAX_REQS value.
57+
58+
`multiplex` enables or disables request multiplexing on a single connection. This setting is used to provide the FCGI_MPXS_CONNS value.
59+
60+
`valueMap` maps FastCGI value names to keys in the `config` object. For more information read [the next section](#fastcgi-values)
61+
62+
FastCGI values
63+
--------------
64+
65+
FastCGI clients can query configuration values from applications with FCGI_GET_VALUES records. Those records contain a sequence of key-value pairs with empty values; the application must fetch the corresponding values for each key and send the data back to the client.
66+
67+
This module retrieves automatically values for standard keys (`FCGI_MAX_CONNS`, `FCGI_MAX_REQS`, `FCGI_MPXS_CONNS`) from server configuration.
68+
69+
To provide additional values, add them to the configuration object and add entries to the `valueMap` option mapping value names to keys in the config object. For example:
70+
71+
```js
72+
fcgi.createServer(function (req, res) { /* ... */ }, {
73+
additionalValue: 1350,
74+
valueMap: {
75+
'ADDITIONAL_VALUE': 'additionalValue'
76+
}
77+
});
78+
```
79+
80+
**WARNING: This `valueMap` thing is complete nonsense and is definitely going to change in the next release.**
81+
82+
Request URL components
83+
----------------------
84+
85+
The `url` parameter of the request object is taken from the `REQUEST_URI` CGI variable, which is non-standard. If `REQUEST_URI` is missing, the url is built by joining three CGI variables:
86+
87+
- [`SCRIPT_NAME`](https://tools.ietf.org/html/rfc3875#section-4.1.13)
88+
- [`PATH_INFO`](https://tools.ietf.org/html/rfc3875#section-4.1.5)
89+
- [`QUERY_STRING`](https://tools.ietf.org/html/rfc3875#section-4.1.7)
90+
91+
For more information read [section 4.1](https://tools.ietf.org/html/rfc3875#section-4.1) of the CGI spec.
92+
93+
Authorizer and filter requests
94+
------------------------------
95+
96+
Authorizer requests have no url. Response objects for the authorizer role expose three additional methods:
97+
98+
- `setVariable(name, value)`: sets CGI variables to be passed to subsequent request handlers.
99+
- `allow()`: responds with 200 (OK) status code.
100+
- `deny()`: responds with 403 (Forbidden) status code.
101+
102+
Filter requests have an additional data stream exposed by the `data` property of [the socket object](#the-socket-object) (`req.socket.data`).
47103

48104
The socket object
49105
-----------------
@@ -53,9 +109,23 @@ and translates writes to stdout FastCGI records.
53109
The object also emulates the public API of `net.Socket`. Address fields contain HTTP server and client address and port (`localAddress`, `localPort`, `remoteAddress`, `remotePort` properties and the `address` method).
54110

55111
The socket object exposes three additional properties:
56-
* `params` is a dictionary of raw CGI params.
57-
* `dataStream` implements `stream.Readable`, exposes the FastCGI data stream for the filter role.
58-
* `errorStream` implements `stream.Writable`, translates writes to stderr FastCGI Records.
112+
- `params` is a dictionary of raw CGI params.
113+
- `dataStream` implements `stream.Readable`, exposes the FastCGI data stream for the filter role.
114+
- `errorStream` implements `stream.Writable`, translates writes to stderr FastCGI Records.
115+
116+
http module compatibility
117+
-------------------------
118+
119+
The API is almost compatible with http module from node v0.12 all the way to v6.2 (the current version). Only the server API is implemented.
120+
121+
Differences:
122+
- A FastCGI server will never emit `'checkContinue'` and `'connect'` events because `CONNECT` method and `Expect: 100-continue` headers should be handled by the front-end http server
123+
- The `'upgrade'` event is not currently implemented. Typically upgrade/websocket requests won't work with FastCGI applications because of input/output buffering.
124+
- `server.listen()` can be called without arguments (or with a callback as the only argument) to listen on the default FastCGI socket `{ fd: 0 }`.
125+
- `server.maxHeadersCount` is useless
126+
- `req.socket` [is not a real socket](#the-socket-object).
127+
- `req.trailers` will always be empty: CGI scripts never receive trailers
128+
- `res.writeContinue()` works as expected but should not be used. See first item
59129

60130
License
61131
=======

0 commit comments

Comments
 (0)