xmlhttprequest
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -1,16 +0,27 @@ | ||
{ "name" : "xmlhttprequest" | ||
, "description" : "XMLHttpRequest for Node" | ||
, "version" : "1.3.0" | ||
, "author" : "Dan DeFelippi" | ||
, "licenses" : | ||
[ { "type" : "MIT" | ||
, "url" : "http://creativecommons.org/licenses/MIT/" | ||
} | ||
] | ||
, "repository" : | ||
{ "type" : "git" | ||
, "url" : "git://github.com/driverdan/node-XMLHttpRequest.git" | ||
{ | ||
"name": "xmlhttprequest" | ||
, "description": "XMLHttpRequest for Node" | ||
, "version": "1.4.0" | ||
, "author": { | ||
"name": "Dan DeFelippi" | ||
, "url": "http://driverdan.com" | ||
} | ||
, "engine" : [ "node >=0.4.0" ] | ||
, "main" : "./XMLHttpRequest.js" | ||
, "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" | ||
} | ||
, "directories": { | ||
"lib": "./lib" | ||
, "example": "./example" | ||
} | ||
, "main": "./lib/XMLHttpRequest.js" | ||
} |
# node-XMLHttpRequest # | ||
node-XMLHttpRequest is a wrapper for the built-in http client to emulate the browser XMLHttpRequest object. | ||
node-XMLHttpRequest is a wrapper for the built-in http client to emulate the | ||
browser XMLHttpRequest object. | ||
This can be used with JS designed for browsers to improve reuse of code and allow the use of existing libraries. | ||
This can be used with JS designed for browsers to improve reuse of code and | ||
allow the use of existing libraries. | ||
Note: This library currently conforms to [XMLHttpRequest 1](http://www.w3.org/TR/XMLHttpRequest/). Version 2.0 will target [XMLHttpRequest Level 2](http://www.w3.org/TR/XMLHttpRequest2/). | ||
## Usage ## | ||
Here's how to include the module in your project and use as the browser-based XHR object. | ||
var XMLHttpRequest = require("XMLHttpRequest").XMLHttpRequest; | ||
Here's how to include the module in your project and use as the browser-based | ||
XHR object. | ||
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; | ||
var xhr = new XMLHttpRequest(); | ||
Refer to [W3C specs](http://www.w3.org/TR/XMLHttpRequest/) for XHR methods. | ||
Note: use the lowercase string "xmlhttprequest" in your require(). On | ||
case-sensitive systems (eg Linux) using uppercase letters won't work. | ||
## Versions ## | ||
Prior to 1.4.0 version numbers were arbitrary. From 1.4.0 on they conform to | ||
the standard major.minor.bugfix. 1.x shouldn't necessarily be considered | ||
stable just because it's above 0.x. | ||
Since the XMLHttpRequest API is stable this library's API is stable as | ||
well. Major version numbers indicate significant core code changes. | ||
Minor versions indicate minor core code changes or better conformity to | ||
the W3C spec. | ||
## Supports ## | ||
* Async and synchronous requests | ||
* GET, POST, and PUT requests | ||
* All native methods (open, send, abort, getRequestHeader, | ||
getAllRequestHeaders) | ||
* GET, POST, PUT, and DELETE requests | ||
* All spec methods (open, send, abort, getRequestHeader, | ||
getAllRequestHeaders, event methods) | ||
* Requests to all domains | ||
## TODO ## | ||
## Known Issues / Missing Features ## | ||
* Add basic authentication | ||
* Additional unit tests | ||
* Possibly move from http to tcp for more flexibility | ||
* DELETE requests aren't working | ||
* XML parsing | ||
For a list of open issues or to report your own visit the [github issues | ||
page](https://github.com/driverdan/node-XMLHttpRequest/issues). | ||
* Local file access may have unexpected results for non-UTF8 files | ||
* Synchronous requests don't set headers properly | ||
* Synchronous requests freeze node while waiting for response (But that's what you want, right? Stick with async!). | ||
* Some events are missing, such as abort | ||
* getRequestHeader is case-sensitive | ||
* Cookies aren't persisted between requests | ||
* Missing XML support | ||
* Missing basic auth |
var sys = require("util") | ||
,assert = require("assert") | ||
,XMLHttpRequest = require("../XMLHttpRequest").XMLHttpRequest | ||
,xhr = new XMLHttpRequest(); | ||
, assert = require("assert") | ||
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest | ||
, xhr = new XMLHttpRequest(); | ||
@@ -6,0 +6,0 @@ // Test constant values |
var sys = require("util") | ||
,assert = require("assert") | ||
,XMLHttpRequest = require("../XMLHttpRequest").XMLHttpRequest | ||
,xhr = new XMLHttpRequest() | ||
,http = require("http"); | ||
, assert = require("assert") | ||
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest | ||
, xhr = new XMLHttpRequest() | ||
, http = require("http"); | ||
@@ -15,3 +15,8 @@ // Test server | ||
"Content-Type": "text/plain", | ||
"Content-Length": Buffer.byteLength(body) | ||
"Content-Length": Buffer.byteLength(body), | ||
// Set cookie headers to see if they're correctly suppressed | ||
// Actual values don't matter | ||
"Set-Cookie": "foo=bar", | ||
"Set-Cookie2": "bar=baz", | ||
"Connection": "close" | ||
}); | ||
@@ -30,2 +35,8 @@ res.write("Hello World"); | ||
// Test case insensitivity | ||
assert.equal('text/plain', this.getResponseHeader('Content-Type')); | ||
assert.equal('text/plain', this.getResponseHeader('Content-type')); | ||
assert.equal('text/plain', this.getResponseHeader('content-Type')); | ||
assert.equal('text/plain', this.getResponseHeader('content-type')); | ||
// Test aborted getAllResponseHeaders | ||
@@ -41,4 +52,10 @@ this.abort(); | ||
assert.equal(null, xhr.getResponseHeader("Content-Type")); | ||
xhr.open("GET", "http://localhost:8000/"); | ||
xhr.setRequestHeader("X-Test", "Foobar"); | ||
xhr.send(); | ||
try { | ||
xhr.open("GET", "http://localhost:8000/"); | ||
xhr.setRequestHeader("X-Test", "Foobar"); | ||
// Test getRequestHeader | ||
assert.equal("Foobar", xhr.getRequestHeader("X-Test")); | ||
xhr.send(); | ||
} catch(e) { | ||
console.log("ERROR: Exception raised", e); | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
24889
12
721
54
7