Listen for IPP requests on a given port and proxy requests to a real IPP printer. Allows for spying on the traffic between the client and the server.
npm install ipp-spy --save
Start an IPP printer spy on port 3000 and proxy all requests to
example.com:
var spy = require('ipp-spy')
var opts = {
port: 3000
forwardHost: 'example.com', // defaults to localhost
forwardPort: 631 // default to 631
}
spy(opts, function (operation, document) {
console.log('New IPP operation:', operation)
var bytes = 0
document.on('data', function (chunk) {
bytes += chunk.length
})
document.on('end', function () {
console.log('Attached document size: %d bytes', bytes)
})
})
The module exposes a generator function which creates a new spy proxy. An EventEmitter is returned:
var server = spy(options[, onOperation])
Options:
port - the port that the spy should listen onforwardHost - the host to forward requests to (defaults to
localhost)forwardPort - the port to forward requests to (defaults to 631)The optional onOperation callback argument will be attached to the
operation event emitted by the returned EventEmitter.
The returned EventEmitter can emmit the following events:
function (client, server) {}
Emitted every time a new TCP connection is made to the spy proxy.
client - a TCP socket streaming the data coming from the clientserver - a TCP socket streaming the data returned from the serverfunction (operation, document) {}
Emitted every time an IPP request is sent to the spy.
The callback is called with two arguments:
operation - the IPP opperation metadata. See
ipp-encoder
for detailsdocument - a readable stream containing the body of the IPP request
(i.e. the document being printed)MIT