Skip to content
Browse files

support arraybuffer request bodies

  • Loading branch information...
1 parent b98b44b commit 10019e0501243cfb5991198c7053e51fd5d91ed2 @maxogden maxogden committed Aug 1, 2012
Showing with 17 additions and 3 deletions.
  1. +17 −3 lib/request.js
View
20 lib/request.js
@@ -4,7 +4,7 @@ var Response = require('./response');
var Request = module.exports = function (xhr, params) {
var self = this;
self.xhr = xhr;
- self.body = '';
+ self.body = [];
var uri = params.host + ':' + params.port + (params.path || '/');
@@ -52,12 +52,26 @@ Request.prototype.setHeader = function (key, value) {
};
Request.prototype.write = function (s) {
- this.body += s;
+ this.body.push(s);
+};
+
+Request.prototype.getBody = function () {
+ if (this.body.length === 0) return;
+ if (typeof(this.body[0]) === "string") return this.body.join('');
+ if (this.body[0].toString().match(/Array/)) {
+ var first = false;
+ this.body.forEach(function(ary) {
+ if (!first) return first = ary;
+ first.concat(ary);
+ })
+ return first;
+ }
+ return this.body;
};
Request.prototype.end = function (s) {
if (s !== undefined) this.write(s);
- this.xhr.send(this.body);
+ this.xhr.send(this.getBody());
};
// Taken from http://dxr.mozilla.org/mozilla/mozilla-central/content/base/src/nsXMLHttpRequest.cpp.html

0 comments on commit 10019e0

Please sign in to comment.
Something went wrong with that request. Please try again.