Server : nginx/1.18.0 System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/ecommerce/node_modules/sockjs-client/lib/transport/driver/ |
'use strict';
var EventEmitter = require('events').EventEmitter
, inherits = require('inherits')
, http = require('http')
, https = require('https')
, URL = require('url-parse')
;
var debug = function() {};
if (process.env.NODE_ENV !== 'production') {
debug = require('debug')('sockjs-client:driver:xhr');
}
function XhrDriver(method, url, payload, opts) {
debug(method, url, payload);
var self = this;
EventEmitter.call(this);
var parsedUrl = new URL(url);
var options = {
method: method
, hostname: parsedUrl.hostname.replace(/\[|\]/g, '')
, port: parsedUrl.port
, path: parsedUrl.pathname + (parsedUrl.query || '')
, headers: opts && opts.headers
, agent: false
};
var protocol = parsedUrl.protocol === 'https:' ? https : http;
this.req = protocol.request(options, function(res) {
res.setEncoding('utf8');
var responseText = '';
res.on('data', function(chunk) {
debug('data', chunk);
responseText += chunk;
self.emit('chunk', 200, responseText);
});
res.once('end', function() {
debug('end');
self.emit('finish', res.statusCode, responseText);
self.req = null;
});
});
this.req.on('error', function(e) {
debug('error', e);
self.emit('finish', 0, e.message);
});
if (payload) {
this.req.write(payload);
}
this.req.end();
}
inherits(XhrDriver, EventEmitter);
XhrDriver.prototype.close = function() {
debug('close');
this.removeAllListeners();
if (this.req) {
this.req.abort();
this.req = null;
}
};
XhrDriver.enabled = true;
XhrDriver.supportsCORS = true;
module.exports = XhrDriver;