2016-09-15 13:59:40 +00:00
|
|
|
'use strict'
|
|
|
|
|
2016-09-19 09:21:09 +00:00
|
|
|
const {EventEmitter} = require('events')
|
2016-09-15 13:59:40 +00:00
|
|
|
const binding = process.atomBinding('net')
|
2016-09-19 09:21:09 +00:00
|
|
|
const {net, Net} = binding
|
|
|
|
const {URLRequest} = net
|
2016-09-15 13:59:40 +00:00
|
|
|
|
2016-09-19 09:21:09 +00:00
|
|
|
Object.setPrototypeOf(Net.prototype, EventEmitter.prototype)
|
|
|
|
Object.setPrototypeOf(URLRequest.prototype, EventEmitter.prototype)
|
|
|
|
|
2016-09-19 13:06:13 +00:00
|
|
|
class URLResponse extends EventEmitter {
|
|
|
|
constructor(request) {
|
|
|
|
super();
|
|
|
|
this.request = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
get statusCode() {
|
|
|
|
return this.request.statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
get statusMessage() {
|
|
|
|
return this.request.statusMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
get headers() {
|
|
|
|
return this.request.responseHeaders;
|
|
|
|
}
|
|
|
|
|
|
|
|
get httpVersion() {
|
|
|
|
return this.request.responseHttpVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Net.prototype.request = function(options, callback) {
|
|
|
|
let request = new URLRequest(options)
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
request.once('response', callback)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return request
|
|
|
|
}
|
|
|
|
|
|
|
|
URLRequest.prototype._emitResponse = function() {
|
|
|
|
this.response = new URLResponse(this);
|
|
|
|
this.emit('response', this.response);
|
|
|
|
}
|
|
|
|
|
2016-09-19 09:21:09 +00:00
|
|
|
module.exports = net
|
2016-09-15 13:59:40 +00:00
|
|
|
|