xmlhttprequest-ssl
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -133,2 +133,3 @@ /** | ||
this.responseXML = ""; | ||
this.response = Buffer.alloc(0); | ||
this.status = null; | ||
@@ -326,3 +327,3 @@ this.statusText = null; | ||
if (settings.async) { | ||
fs.readFile(unescape(url.pathname), 'utf8', function(error, data) { | ||
fs.readFile(unescape(url.pathname), function(error, data) { | ||
if (error) { | ||
@@ -332,3 +333,4 @@ self.handleError(error, error.errno || -1); | ||
self.status = 200; | ||
self.responseText = data; | ||
self.responseText = data.toString('utf8'); | ||
self.response = data; | ||
setState(self.DONE); | ||
@@ -339,3 +341,4 @@ } | ||
try { | ||
this.responseText = fs.readFileSync(unescape(url.pathname), 'utf8'); | ||
this.response = fs.readFileSync(unescape(url.pathname)); | ||
this.responseText = this.response.toString('utf8'); | ||
this.status = 200; | ||
@@ -459,6 +462,2 @@ setState(self.DONE); | ||
if (response && response.setEncoding) { | ||
response.setEncoding("utf8"); | ||
} | ||
setState(self.HEADERS_RECEIVED); | ||
@@ -470,3 +469,5 @@ self.status = response.statusCode; | ||
if (chunk) { | ||
self.responseText += chunk; | ||
var data = Buffer.from(chunk); | ||
self.responseText += data.toString('utf8'); | ||
self.response = Buffer.concat([self.response, data]); | ||
} | ||
@@ -526,9 +527,11 @@ // Don't emit state changes if the connection has been aborted. | ||
+ "var responseText = '';" | ||
+ "var responseData = Buffer.alloc(0);" | ||
+ "var req = doRequest(options, function(response) {" | ||
+ "response.setEncoding('utf8');" | ||
+ "response.on('data', function(chunk) {" | ||
+ " responseText += chunk;" | ||
+ " var data = Buffer.from(chunk);" | ||
+ " responseText += data.toString('utf8');" | ||
+ " responseData = Buffer.concat([responseData, data]);" | ||
+ "});" | ||
+ "response.on('end', function() {" | ||
+ "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');" | ||
+ "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText, data: responseData.toString('base64')}}), 'utf8');" | ||
+ "fs.unlinkSync('" + syncFile + "');" | ||
@@ -559,3 +562,3 @@ + "});" | ||
// If the file returned an error, handle it | ||
var errorObj = self.responseText.replace(/^NODE-XMLHTTPREQUEST-ERROR:/, ""); | ||
var errorObj = JSON.parse(self.responseText.replace(/^NODE-XMLHTTPREQUEST-ERROR:/, "")); | ||
self.handleError(errorObj, 503); | ||
@@ -565,4 +568,10 @@ } else { | ||
self.status = self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:([0-9]*),.*/, "$1"); | ||
self.responseText = self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:[0-9]*,(.*)/, "$1"); | ||
setState(self.DONE); | ||
var resp = JSON.parse(self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:[0-9]*,(.*)/, "$1")); | ||
response = { | ||
statusCode: self.status, | ||
headers: resp.data.headers | ||
}; | ||
self.responseText = resp.data.text; | ||
self.response = Buffer.from(resp.data.data, 'base64'); | ||
setState(self.DONE, true); | ||
} | ||
@@ -596,2 +605,3 @@ } | ||
this.responseXML = ""; | ||
this.response = Buffer.alloc(0); | ||
@@ -635,5 +645,5 @@ errorFlag = abortedFlag = true | ||
*/ | ||
this.dispatchEvent = function(event) { | ||
this.dispatchEvent = function (event) { | ||
if (typeof self["on" + event] === "function") { | ||
if (this.readyState === this.DONE) | ||
if (this.readyState === this.DONE && settings.async) | ||
setImmediate(function() { self["on" + event]() }) | ||
@@ -640,0 +650,0 @@ else |
{ | ||
"name": "xmlhttprequest-ssl", | ||
"description": "XMLHttpRequest for Node", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"author": { | ||
@@ -27,3 +27,3 @@ "name": "Michael de Wit" | ||
"scripts": { | ||
"test": "cd ./tests && node test-constants.js && node test-events.js && node test-exceptions.js && node test-headers.js && node test-redirect-302.js && node test-redirect-303.js && node test-redirect-307.js && node test-request-methods.js && node test-request-protocols.js" | ||
"test": "cd ./tests && node test-constants.js && node test-events.js && node test-exceptions.js && node test-headers.js && node test-redirect-302.js && node test-redirect-303.js && node test-redirect-307.js && node test-request-methods.js && node test-request-protocols-txt-data.js && node test-request-protocols-binary-data.js && node test-sync-response.js" | ||
}, | ||
@@ -30,0 +30,0 @@ "directories": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40013
20
1081
11