Simple SCGI client.
scgi-stream lets you talk to scgi-speaking services without having to go through an intermediate HTTP server.
Available via npm:
$ npm install scgi-stream
Or via git:
$ git clone git://github.com/deoxxa/scgi-stream.git node_modules/scgi-stream
request
Makes an SCGI request. Returns an SCGIRequest
object. Also does some wiring
for you so that the request returned will emit a response
event when the
response begins to arrive. See the example section below for more information on
how this works.
scgi.request(options);
var scgi = require("scgi-stream");
scgi.request(options);
Arguments
- options - an object specifying options for the request and response.
Available options are
stream
,host
,port
,path
,method
, andheaders
.stream
is optionally a stream object. Ifstream
is not specified,host
andport
, which are a string and a number respectively, will be used to construct a TCP socket.path
andmethod
are strings, andheaders
is an object with a predictable structure.
duplex
Makes an SCGI request. Returns a duplex stream that combines both the request
and response parts of the operation. The stream returned will emit the headers
event like a regular SCGIResponse
object, but will not emit a response
event.
scgi.duplex(options);
var scgi = require("scgi-stream");
process.stdin.pipe(scgi.duplex(options)).pipe(process.stdout);
Arguments
- options - same as the options for request
SCGIRequest
A duplex stream representing a request.
new SCGIRequest(options);
var req = new scgi.SCGIRequest({
path: "/",
headers: {
"content-type": "text/plain",
},
});
req.pipe(process.stdout);
req.end("hi there");
Arguments
- options - an object specifying options for the request. Available options
are
path
,method
, andheaders
.
SCGIResponse
A duplex stream that parses and represents a response. Emits a headers
event
when the headers for the stream have been parsed, then passes through all
following data.
new SCGIResponse(options);
var res = new scgi.SCGIResponse();
socket.pipe(res).pipe(process.stdout);
res.on("headers", function(headers) {
console.log(headers);
});
Arguments
- options - an object with the typical
stream.Transform
options such ashighWaterMark
,objectMode
, etc.
Also see example.js.
var scgi = require("scgi-stream");
var req = scgi.request({
host: "127.0.0.1",
port: 17199,
path: "/",
});
req.on("response", function(res) {
res.on("headers", function(headers) {
console.log(headers);
});
res.pipe(process.stdout);
});
req.end("<methodCall><methodName>download_list</methodName></methodCall>");
3-clause BSD. A copy is included with the source.
- GitHub (deoxxa)
- Twitter (@deoxxa)
- ADN (@deoxxa)
- Email (deoxxa@fknsrs.biz)