Fast FastCGI Stream wrapper for reading/writing FCGI records.
Read & write FastCGI records from a node.js stream like a boss.
npm install fastcgi-stream --save
The FastCGI stream library has two main pieces, the
FastCGIStream itself and the records that can be sent and received on it.
FastCGIStream wraps an existing
Stream to send/receive FCGI records on. 99% of the time this is going to be a
var fastcgi = require'fastcgi-stream';var fcgiStream = mySocket;// Send FastCGI records.fcgiStreamwriteRecordrequestId BeginRequestfastcgirecordsBeginRequestrolesRESPONDERfastcgirecordsBeginRequestflagsKEEP_CONN;// Receive FastCGI records.fcgiStreamon'record'ifrequestId == fastcgiconstantsNULL_REQUEST_ID// Management record.elseswitchrecordTYPEcase fastcgirecordsBeginRequestTYPE:// Request beginning. What role are we being asked to fulfill?ifrecordrole == fastcgirecordsBeginRequestroleRESPONDER// Etc...break;;
All record objects live in the
fastcgi.records namespace. Each record will now be listed. The listing will detail the constructor and parameters each record contains.
Constructor args are never mandatory, you can pass as many or as few arguments as you like.
var record = new fastcgi.records.BeginRequest(role, flags);
.role- the role being requested. Possible roles as follows:
.flags- additional flags for the request. There is only one in the specification:
var record = new fastcgi.records.AbortRequest();
var record = new fastcgi.records.EndRequest(appStatus, protocolStatus);
.appStatus- application return status code
.protocolStatus- protocol return status code, can be one of the following:
var params ='Name' 'Value''AnotherName' 'AnotherValue';// Params is optional.var record = Paramsparams;
.params - an array of name/value array pairs
All of these records take the same constructor and have the same properties.
var body = 'String';var record = StdInbody;// .. or ..var body = 'Contents.';var record = StdInbody;
var values = 'Name' 'AnotherName';var record = GetValuesvalues;
.values - array of values being requested
var result ='Name' 'Value''AnotherName' 'AnotherValue';var record = GetValuesResultresult;
.values - array of name/value pairs representing the result.
var record = UnknownTypetype;
.type - the type of record that was not recognized.
node-fastcgi-stream is free and unencumbered public domain software. For more information, see the accompanying UNLICENSE file.