Comparing version 0.0.1 to 0.0.2
@@ -107,3 +107,2 @@ // Generated by CoffeeScript 1.4.0 | ||
this._responseHeaders = null; | ||
this._responseLoweredHeaders = null; | ||
this._aborting = null; | ||
@@ -184,3 +183,2 @@ this._error = null; | ||
this._responseHeaders = null; | ||
this._responseLoweredHeaders = null; | ||
this._loadedBytes = 0; | ||
@@ -250,3 +248,4 @@ this._totalBytes = 0; | ||
} | ||
if (loweredName = this._responseLoweredHeaders[name]) { | ||
loweredName = name.toLowerCase(); | ||
if (loweredName in this._responseHeaders) { | ||
return this._responseHeaders[loweredName]; | ||
@@ -350,5 +349,3 @@ } else { | ||
XMLHttpRequest.prototype._finalizeHeaders = function() { | ||
this._headers['Accept-Charset'] = 'utf-8'; | ||
this._headers['Connection'] = 'keep-alive'; | ||
this._headers['Date'] = (new Date()).toUTCString(); | ||
this._headers['Host'] = this._url.host; | ||
@@ -359,3 +356,3 @@ if (this._anonymous) { | ||
this._headers['User-Agent'] = this._userAgent; | ||
this.upload._finalizeHeaders(this._headers); | ||
this.upload._finalizeHeaders(this._headers, this._loweredHeaders); | ||
return void 0; | ||
@@ -487,3 +484,2 @@ }; | ||
this._responseHeaders = null; | ||
this._responseLoweredHeaders = null; | ||
this._responseParts = null; | ||
@@ -496,3 +492,2 @@ return void 0; | ||
this._responseHeaders = {}; | ||
this._responseLoweredHeaders = {}; | ||
_ref = response.headers; | ||
@@ -505,11 +500,9 @@ for (name in _ref) { | ||
} | ||
if (this._mimeOverride && loweredName === 'content-type') { | ||
if (this._mimeOverride !== null && loweredName === 'content-type') { | ||
value = this._mimeOverride; | ||
} | ||
this._responseHeaders[name] = value; | ||
this._responseLoweredHeaders[loweredName] = value; | ||
this._responseHeaders[loweredName] = value; | ||
} | ||
if (this._mimeOverride && !this._responseLoweredHeaders['content-type']) { | ||
this._responseLoweredHeaders['content-type'] = this._mimeOverride; | ||
this._responseHeaders['Content-Type'] = this._mimeOverride; | ||
if (this._mimeOverride !== null && !('content-type' in this._responseHeaders)) { | ||
this._responseHeaders['content-type'] = this._mimeOverride; | ||
} | ||
@@ -525,10 +518,10 @@ return void 0; | ||
case 'text': | ||
this.responseText = buffer.toString(this._parseResponseEncoding()); | ||
return this.response = this.responseText; | ||
this._parseTextResponse(buffer); | ||
break; | ||
case 'json': | ||
this.responseText = null; | ||
try { | ||
return this.response = JSON.parse(buffer.toString('utf-8')); | ||
this.response = JSON.parse(buffer.toString('utf-8')); | ||
} catch (jsonError) { | ||
return this.response = null; | ||
this.response = null; | ||
} | ||
@@ -538,3 +531,4 @@ break; | ||
this.responseText = null; | ||
return this.response = buffer; | ||
this.response = buffer; | ||
break; | ||
case 'arraybuffer': | ||
@@ -547,13 +541,24 @@ this.responseText = null; | ||
} | ||
return this.response = arrayBuffer; | ||
this.response = arrayBuffer; | ||
break; | ||
default: | ||
this.responseText = buffer.toString(this._parseResponseEncoding()); | ||
return this.response = this.responseText; | ||
this._parseTextResponse(buffer); | ||
} | ||
return void 0; | ||
}; | ||
XMLHttpRequest.prototype._parseTextResponse = function(buffer) { | ||
try { | ||
this.responseText = buffer.toString(this._parseResponseEncoding()); | ||
} catch (e) { | ||
this.responseText = buffer.toString('binary'); | ||
} | ||
this.response = this.responseText; | ||
return void 0; | ||
}; | ||
XMLHttpRequest.prototype._parseResponseEncoding = function() { | ||
var contentType, encoding, match; | ||
encoding = null; | ||
if (contentType = this._responseLoweredHeaders['content-type']) { | ||
if (contentType = this._responseHeaders['content-type']) { | ||
if (match = /\;\s*charset\=(.*)$/.exec(contentType)) { | ||
@@ -665,9 +670,7 @@ return match[1]; | ||
if (typeof data === 'string') { | ||
this._contentType = 'text/plain; charset=UTF-8'; | ||
this._body = new Buffer(data, 'utf-8'); | ||
} else if (Buffer.isBuffer(body)) { | ||
this._contentType = 'application/octet-stream'; | ||
this._contentType = 'text/plain;charset=UTF-8'; | ||
this._body = new Buffer(data, 'utf8'); | ||
} else if (Buffer.isBuffer(data)) { | ||
this._body = data; | ||
} else if (data.buffer && data.buffer instanceof ArrayBuffer) { | ||
this._contentType = 'application/octet-stream'; | ||
body = new Buffer(data.byteLength); | ||
@@ -674,0 +677,0 @@ offset = data.byteOffset; |
{ | ||
"name": "xhr2", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "XMLHttpRequest emulation for node.js", | ||
@@ -5,0 +5,0 @@ "keywords": ["xhr", "xmlhttprequest", "ajax", "browser"], |
@@ -45,2 +45,9 @@ # XMLHttpRequest Emulation for node.js | ||
The other objects that are usually defined in an XHR environment are hanging | ||
off of `XMLHttpRequest`. | ||
```javascript | ||
var XMLHttpRequestUpload = XMLHttpRequest.XMLHttpRequestUpload; | ||
``` | ||
MDN (the Mozilla Developer Network) has a | ||
@@ -50,2 +57,32 @@ [great intro to XMLHttpRequest](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest). | ||
## Features | ||
The following standard features are implemented. | ||
* `http` and `https` URI protocols | ||
* Basic authentication according to the XMLHttpRequest specification | ||
* request and response header management | ||
* `send()` accepts the following data types: String, ArrayBuffer | ||
* `responseType` values: `text`, `json`, `arraybuffer` | ||
* `readystatechange` and download progress events | ||
* `overrideMimeType()` | ||
* `abort()` | ||
* `timeout` | ||
The following node.js extensions are implemented. | ||
* `send()` accepts a node.js Buffer | ||
* Setting `responseType` to `buffer` produces a node.js Buffer | ||
The following standard features are not implemented. | ||
* FormData | ||
* Blob | ||
* `file://` URIs | ||
* automated redirection following | ||
* upload progress events | ||
* synchronous operation | ||
* Same-origin policy checks and CORS | ||
## Versioning | ||
@@ -59,2 +96,39 @@ | ||
## Development | ||
The following commands will get the source tree in a `node-xhr2/` directory and | ||
build the library. | ||
```bash | ||
git clone git://github.com/pwnall/node-xhr2.git | ||
cd node-xhr2 | ||
npm install | ||
npm pack | ||
``` | ||
Installing CoffeeScript globally will let you type `cake` instead of | ||
`node_modules/.bin/cake` | ||
```bash | ||
npm install -g coffee-script | ||
``` | ||
The library comes with unit tests that exercise the XMLHttpRequest API. | ||
```bash | ||
cake test | ||
``` | ||
The tests themselves can be tested by running them in a browser environment, | ||
where a different XMLHttpRequest implementation is available. Both Google | ||
Chrome and Firefox deviate from the specification in small ways, so it's best | ||
to run the tests in both browsers and mentally compute an intersection of the | ||
failing tests. | ||
```bash | ||
cake webtest | ||
BROWSER=firefox cake webtest | ||
``` | ||
## Copyright and License | ||
@@ -61,0 +135,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
93243
25
596
135
3