[Pkg-javascript-commits] [node-xmlhttprequest-ssl] 01/03: Imported Upstream version 1.6.0

Thorsten Alteholz alteholz at moszumanska.debian.org
Sun Jun 19 17:22:33 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-xmlhttprequest-ssl.

commit 4eeecf5f2f740ea4fdbd0df395669da25bcf7610
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sun Jun 19 19:16:45 2016 +0200

    Imported Upstream version 1.6.0
---
 README.md                       |  4 ---
 lib/XMLHttpRequest.js           | 67 ++++++-----------------------------------
 package.json                    | 56 +++++++++++++++-------------------
 tests/test-exceptions.js        |  5 ++-
 tests/test-request-protocols.js |  2 ++
 tests/testdata.txt              |  2 +-
 6 files changed, 40 insertions(+), 96 deletions(-)

diff --git a/README.md b/README.md
index 73f8876..b989434 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,5 @@
 # node-XMLHttpRequest #
 
-Fork of [node-XMLHttpRequest](https://github.com/driverdan/node-XMLHttpRequest) by [driverdan](http://driverdan.com). Forked and published to npm because a [pull request](https://github.com/rase-/node-XMLHttpRequest/commit/a6b6f296e0a8278165c2d0270d9840b54d5eeadd) is not being created and merged. Changes made by [rase-](https://github.com/rase-/node-XMLHttpRequest/tree/add/ssl-support) are needed for [engine.io-client](https://github.com/Automattic/engine.io-client).
-
-# Original README #
-
 node-XMLHttpRequest is a wrapper for the built-in http client to emulate the
 browser XMLHttpRequest object.
 
diff --git a/lib/XMLHttpRequest.js b/lib/XMLHttpRequest.js
index 8ff9415..5c99b24 100644
--- a/lib/XMLHttpRequest.js
+++ b/lib/XMLHttpRequest.js
@@ -11,32 +11,11 @@
  * @license MIT
  */
 
-var fs = require('fs');
-var Url = require('url');
-var spawn = require('child_process').spawn;
-
-/**
- * Module exports.
- */
-
-module.exports = XMLHttpRequest;
-
-// backwards-compat
-XMLHttpRequest.XMLHttpRequest = XMLHttpRequest;
-
-/**
- * `XMLHttpRequest` constructor.
- *
- * Supported options for the `opts` object are:
- *
- *  - `agent`: An http.Agent instance; http.globalAgent may be used; if 'undefined', agent usage is disabled
- *
- * @param {Object} opts optional "options" object
- */
-
-function XMLHttpRequest(opts) {
-  "use strict";
+var Url = require("url")
+  , spawn = require("child_process").spawn
+  , fs = require('fs');
 
+exports.XMLHttpRequest = function() {
   /**
    * Private variables
    */
@@ -58,7 +37,7 @@ function XMLHttpRequest(opts) {
   // Set some default headers
   var defaultHeaders = {
     "User-Agent": "node-XMLHttpRequest",
-    "Accept": "*/*"
+    "Accept": "*/*",
   };
 
   var headers = defaultHeaders;
@@ -202,23 +181,19 @@ function XMLHttpRequest(opts) {
    *
    * @param string header Header name
    * @param string value Header value
-   * @return boolean Header added
    */
   this.setRequestHeader = function(header, value) {
     if (this.readyState != this.OPENED) {
       throw "INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN";
-      return false;
     }
     if (!isAllowedHttpHeader(header)) {
       console.warn('Refused to set unsafe header "' + header + '"');
-      return false;
+      return;
     }
     if (sendFlag) {
       throw "INVALID_STATE_ERR: send flag is true";
-      return false;
     }
     headers[header] = value;
-    return true;
   };
 
   /**
@@ -378,29 +353,15 @@ function XMLHttpRequest(opts) {
       headers["Content-Length"] = 0;
     }
 
-    var agent = false;
-    if (opts && opts.agent) {
-      agent = opts.agent;
-    }
     var options = {
       host: host,
       port: port,
       path: uri,
       method: settings.method,
       headers: headers,
-      agent: agent
+      agent: false
     };
 
-    if (ssl) {
-      options.pfx = opts.pfx;
-      options.key = opts.key;
-      options.passphrase = opts.passphrase;
-      options.cert = opts.cert;
-      options.ca = opts.ca;
-      options.ciphers = opts.ciphers;
-      options.rejectUnauthorized = opts.rejectUnauthorized;
-    }
-
     // Reset error flag
     errorFlag = false;
 
@@ -416,7 +377,7 @@ function XMLHttpRequest(opts) {
       self.dispatchEvent("readystatechange");
 
       // Handler for the response
-      var responseHandler = function(resp) {
+      function responseHandler(resp) {
         // Set response var to the response we got back
         // This is so it remains accessable outside this scope
         response = resp;
@@ -437,16 +398,6 @@ function XMLHttpRequest(opts) {
             headers: headers
           };
 
-          if (ssl) {
-            newOptions.pfx = opts.pfx;
-            newOptions.key = opts.key;
-            newOptions.passphrase = opts.passphrase;
-            newOptions.cert = opts.cert;
-            newOptions.ca = opts.ca;
-            newOptions.ciphers = opts.ciphers;
-            newOptions.rejectUnauthorized = opts.rejectUnauthorized;
-          }
-
           // Issue the new request
           request = doRequest(newOptions, responseHandler).on('error', errorHandler);
           request.end();
@@ -484,7 +435,7 @@ function XMLHttpRequest(opts) {
       }
 
       // Error handler for the request
-      var errorHandler = function(error) {
+      function errorHandler(error) {
         self.handleError(error);
       }
 
diff --git a/package.json b/package.json
index de0218e..7d2845e 100644
--- a/package.json
+++ b/package.json
@@ -1,35 +1,27 @@
 {
-  "name": "xmlhttprequest-ssl",
-  "description": "XMLHttpRequest for Node",
-  "version": "1.5.2",
-  "author": {
-    "name": "Michael de Wit"
-  },
-  "keywords": [
-    "xhr",
-    "ajax"
-  ],
-  "licenses": [
-    {
-      "type": "MIT",
-      "url": "http://creativecommons.org/licenses/MIT/"
-    }
-  ],
-  "repository": {
-    "type": "git",
-    "url": "git://github.com/mjwwit/node-XMLHttpRequest.git"
-  },
-  "bugs": "http://github.com/mjwwit/node-XMLHttpRequest/issues",
-  "engines": {
+  "name": "xmlhttprequest"
+, "description": "XMLHttpRequest for Node"
+, "version": "1.6.0"
+, "author": {
+    "name": "Dan DeFelippi"
+  , "url": "http://driverdan.com"
+  }
+, "keywords": ["xhr", "ajax"]
+, "licenses": [{
+    "type": "MIT"
+  , "url": "http://creativecommons.org/licenses/MIT/"
+  }]
+, "repository": {
+    "type": "git"
+  , "url": "git://github.com/driverdan/node-XMLHttpRequest.git"
+  }
+, "bugs": "http://github.com/driverdan/node-XMLHttpRequest/issues"
+, "engines": {
     "node": ">=0.4.0"
-  },
-  "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"
-  },
-  "directories": {
-    "lib": "./lib",
-    "example": "./example"
-  },
-  "main": "./lib/XMLHttpRequest.js",
-  "dependencies": {}
+  }
+, "directories": {
+    "lib": "./lib"
+  , "example": "./example"
+  }
+, "main": "./lib/XMLHttpRequest.js"
 }
diff --git a/tests/test-exceptions.js b/tests/test-exceptions.js
index 10eaea2..f1edd71 100644
--- a/tests/test-exceptions.js
+++ b/tests/test-exceptions.js
@@ -44,12 +44,15 @@ var forbiddenRequestHeaders = [
   "trailer",
   "transfer-encoding",
   "upgrade",
+  "user-agent",
   "via"
 ];
 
 for (var i in forbiddenRequestHeaders) {
-  if(xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test") !== false) {
+  try {
+    xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test");
     console.log("ERROR: " + forbiddenRequestHeaders[i] + " should have thrown exception");
+  } catch(e) {
   }
 }
 
diff --git a/tests/test-request-protocols.js b/tests/test-request-protocols.js
index 543917d..cd4e174 100644
--- a/tests/test-request-protocols.js
+++ b/tests/test-request-protocols.js
@@ -8,6 +8,7 @@ xhr = new XMLHttpRequest();
 xhr.onreadystatechange = function() {
   if (this.readyState == 4) {
     assert.equal("Hello World", this.responseText);
+    this.close();
     runSync();
   }
 };
@@ -24,6 +25,7 @@ var runSync = function() {
   xhr.onreadystatechange = function() {
     if (this.readyState == 4) {
       assert.equal("Hello World", this.responseText);
+      this.close();
       sys.puts("done");
     }
   };
diff --git a/tests/testdata.txt b/tests/testdata.txt
index 5e1c309..557db03 100644
--- a/tests/testdata.txt
+++ b/tests/testdata.txt
@@ -1 +1 @@
-Hello World
\ No newline at end of file
+Hello World

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-xmlhttprequest-ssl.git



More information about the Pkg-javascript-commits mailing list