1.9 KiB
protocol
The protocol module can register a new protocol or intercept an existing
protocol, so you can custom the response to the requests for various protocols.
An example of implementing a protocol that has the same effect with the
file:// protocol:
var app = require('app'),
path = require('path');
app.on('will-finish-launching', function() {
var protocol = require('protocol');
protocol.registerProtocol('atom', function(request) {
var url = request.url.substr(7)
return new protocol.RequestFileJob(path.normalize(__dirname + '/' + url));
});
});
Note: This module can only be used after the will-finish-launching event
was emitted.
protocol.registerProtocol(scheme, handler)
schemeStringhandlerFunction
Registers a custom protocol of scheme, the handler would be called with
handler(request) when the a request with registered scheme is made.
You need to return a request job in the handler to specify which type of
response you would like to send.
protocol.unregisterProtocol(scheme)
schemeString
Unregisters the custom protocol of scheme.
protocol.isHandledProtocol(scheme)
schemeString
Returns whether the scheme can be handled already.
protocol.interceptProtocol(scheme, handler)
schemeStringhandlerFunction
Intercepts an existing protocol with scheme, returning null or undefined
in handler would use the original protocol handler to handle the request.
protocol.uninterceptProtocol(scheme)
schemeString
Unintercepts a protocol.
Class: protocol.RequestFileJob(path)
pathString
Create a request job which would query a file of path and set corresponding
mime types.
Class: protocol.RequestStringJob(options)
optionsObjectmimeTypeString - Default istext/plaincharsetString - Default isUTF-8dataString
Create a request job which sends a string as response.