Socket
Socket
Sign inDemoInstall

xmlhttprequest

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmlhttprequest - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

LICENSE

76

lib/XMLHttpRequest.js

@@ -27,3 +27,2 @@ /**

// Holds http.js objects
var client;
var request;

@@ -158,3 +157,2 @@ var response;

throw "SecurityError: Request method not allowed";
return;
}

@@ -181,3 +179,3 @@

disableHeaderCheck = state;
}
};

@@ -255,3 +253,3 @@ /**

return "";
}
};

@@ -274,3 +272,3 @@ /**

var url = Url.parse(settings.url);
var host;
// Determine the server

@@ -282,3 +280,3 @@ switch (url.protocol) {

case 'http:':
var host = url.hostname;
host = url.hostname;
break;

@@ -292,3 +290,3 @@

case '':
var host = "localhost";
host = "localhost";
break;

@@ -354,3 +352,3 @@

} else if (data) {
headers["Content-Length"] = Buffer.byteLength(data);
headers["Content-Length"] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data);

@@ -389,5 +387,31 @@ if (!headers["Content-Type"]) {

// Create the request
request = doRequest(options, function(resp) {
// Handler for the response
function responseHandler(resp) {
// Set response var to the response we got back
// This is so it remains accessable outside this scope
response = resp;
// Check for redirect
// @TODO Prevent looped redirects
if (response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) {
// Change URL to the redirect location
settings.url = response.headers.location;
var url = Url.parse(settings.url);
// Set host var in case it's used later
host = url.hostname;
// Options for the new request
var newOptions = {
hostname: url.hostname,
port: url.port,
path: url.path,
method: response.statusCode === 303 ? 'GET' : settings.method,
headers: headers
};
// Issue the new request
request = doRequest(newOptions, responseHandler).on('error', errorHandler);
request.end();
// @TODO Check if an XHR event needs to be fired here
return;
}
response.setEncoding("utf8");

@@ -420,6 +444,12 @@

});
}).on('error', function(error) {
}
// Error handler for the request
function errorHandler(error) {
self.handleError(error);
});
}
// Create the request
request = doRequest(options, responseHandler).on('error', errorHandler);
// Node 0.4 and later won't accept empty data. Make sure it's needed.

@@ -435,2 +465,3 @@ if (data) {

// Create a temporary file for communication with the other Node process
var contentFile = ".node-xmlhttprequest-content-" + process.pid;
var syncFile = ".node-xmlhttprequest-sync-" + process.pid;

@@ -446,12 +477,15 @@ fs.writeFileSync(syncFile, "", "utf8");

+ "response.on('data', function(chunk) {"
+ "responseText += chunk;"
+ " responseText += chunk;"
+ "});"
+ "response.on('end', function() {"
+ "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
+ "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
+ "fs.unlinkSync('" + syncFile + "');"
+ "});"
+ "response.on('error', function(error) {"
+ "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
+ "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
+ "fs.unlinkSync('" + syncFile + "');"
+ "});"
+ "}).on('error', function(error) {"
+ "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
+ "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
+ "fs.unlinkSync('" + syncFile + "');"
+ "});"

@@ -461,10 +495,12 @@ + (data ? "req.write('" + data.replace(/'/g, "\\'") + "');":"")

// Start the other Node Process, executing this string
syncProc = spawn(process.argv[0], ["-e", execString]);
while((self.responseText = fs.readFileSync(syncFile, 'utf8')) == "") {
// Wait while the file is empty
var syncProc = spawn(process.argv[0], ["-e", execString]);
var statusText;
while(fs.existsSync(syncFile)) {
// Wait while the sync file is empty
}
self.responseText = fs.readFileSync(contentFile, 'utf8');
// Kill the child process once the file has data
syncProc.stdin.end();
// Remove the temporary file
fs.unlinkSync(syncFile);
fs.unlinkSync(contentFile);
if (self.responseText.match(/^NODE-XMLHTTPREQUEST-ERROR:/)) {

@@ -471,0 +507,0 @@ // If the file returned an error, handle it

{
"name": "xmlhttprequest"
, "description": "XMLHttpRequest for Node"
, "version": "1.5.0"
, "version": "1.6.0"
, "author": {

@@ -6,0 +6,0 @@ "name": "Dan DeFelippi"

@@ -33,2 +33,6 @@ # node-XMLHttpRequest #

## License ##
MIT license. See LICENSE for full details.
## Supports ##

@@ -35,0 +39,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc