Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "xhr2",
"version": "0.1.4",
"description": "XMLHttpRequest emulation for node.js",
"keywords": ["xhr", "xmlhttprequest", "ajax", "browser"],
"keywords": [
"xhr",
"xmlhttprequest",
"ajax",
"browser"
],
"homepage": "https://github.com/pwnall/node-xhr2",
"author": "Victor Costan <[email protected]> (http://www.costan.us)",
"contributors": [
Expand All @@ -21,6 +26,7 @@
"node": ">= 0.6"
},
"dependencies": {
"form-data": "^2.1.4"
},
"devDependencies": {
"async": ">= 1.4.2",
Expand Down
3 changes: 3 additions & 0 deletions src/001-xml_http_request.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -780,3 +780,6 @@ module.exports = XMLHttpRequest
# following usage pattern:
# var XMLHttpRequest = require('xhr-library-name').XMLHttpRequest
XMLHttpRequest.XMLHttpRequest = XMLHttpRequest


XMLHttpRequest.FormData = require('form-data')
9 changes: 9 additions & 0 deletions src/xml_http_request_upload.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FormData = require('form-data')

# @see http://xhr.spec.whatwg.org/#interface-xmlhttprequest
class XMLHttpRequestUpload extends XMLHttpRequestEventTarget
# @private
Expand Down Expand Up @@ -49,6 +51,13 @@ class XMLHttpRequestUpload extends XMLHttpRequestEventTarget
view = new Uint8Array data.buffer
body[i] = view[i + offset] for i in [0...data.byteLength]
@_body = body
else if data instanceof FormData
body = ''
data.on('data', (data) -> body += data.toString())
data.resume()
while !data.pauseStreams then
@_contentType = data.getHeaders()['content-type']
@_body = body
else
# NOTE: diverging from the XHR specification of coercing everything else
# to Strings via toString() because that behavior masks bugs and is
Expand Down