2014-10-30 22:27:29 +08:00
|
|
|
app = require 'app'
|
|
|
|
throw new Error('Can not initialize protocol module before app is ready') unless app.isReady()
|
|
|
|
|
2014-04-21 16:33:32 +08:00
|
|
|
protocol = process.atomBinding('protocol').protocol
|
2013-08-29 20:38:04 +08:00
|
|
|
EventEmitter = require('events').EventEmitter
|
2013-08-25 15:07:07 +08:00
|
|
|
|
2014-04-21 16:33:32 +08:00
|
|
|
protocol.__proto__ = EventEmitter.prototype
|
2013-08-29 20:38:04 +08:00
|
|
|
|
|
|
|
protocol.RequestStringJob =
|
2013-08-25 15:07:07 +08:00
|
|
|
class RequestStringJob
|
|
|
|
constructor: ({mimeType, charset, data}) ->
|
|
|
|
if typeof data isnt 'string' and not data instanceof Buffer
|
|
|
|
throw new TypeError('Data should be string or Buffer')
|
|
|
|
|
|
|
|
@mimeType = mimeType ? 'text/plain'
|
|
|
|
@charset = charset ? 'UTF-8'
|
|
|
|
@data = String data
|
2013-08-25 16:06:29 +08:00
|
|
|
|
2015-03-16 18:23:45 +05:30
|
|
|
protocol.RequestBufferJob =
|
|
|
|
class RequestBufferJob
|
|
|
|
constructor: ({mimeType, encoding, data}) ->
|
|
|
|
if not data instanceof Buffer
|
|
|
|
throw new TypeError('Data should be Buffer')
|
|
|
|
|
|
|
|
@mimeType = mimeType ? 'application/octet-stream'
|
|
|
|
@encoding = encoding ? 'utf8'
|
|
|
|
@data = new Buffer(data)
|
|
|
|
|
2013-08-29 20:38:04 +08:00
|
|
|
protocol.RequestFileJob =
|
2013-08-25 16:06:29 +08:00
|
|
|
class RequestFileJob
|
|
|
|
constructor: (@path) ->
|
2013-08-29 20:38:04 +08:00
|
|
|
|
2015-05-07 13:12:35 +05:30
|
|
|
protocol.RequestErrorJob =
|
|
|
|
class RequestErrorJob
|
|
|
|
constructor: (@error) ->
|
|
|
|
|
2015-05-29 21:24:00 +05:30
|
|
|
protocol.RequestHttpJob =
|
|
|
|
class RequestHttpJob
|
2015-06-17 11:20:09 +08:00
|
|
|
constructor: ({@url, @method, @referrer}) ->
|
2015-05-29 21:24:00 +05:30
|
|
|
|
2013-08-29 20:38:04 +08:00
|
|
|
module.exports = protocol
|