Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for firefox blob -> array buffer and back again #64

Merged
merged 1 commit into from
Apr 19, 2014
Merged
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
32 changes: 23 additions & 9 deletions dist/0.6/xdomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ getFrame = function(origin, proxyPath) {

initMaster = function() {
return xhook.before(function(request, callback) {
var frame, obj, p, socket;
var frame, obj, p, reader, socket;
p = parseUrl(request.url);
if (!p || p.origin === currentOrigin) {
return callback();
Expand Down Expand Up @@ -507,15 +507,26 @@ initMaster = function() {
});
obj = strip(request);
obj.headers = request.headers;
if (request.withCredentials) {
obj.credentials = document.cookie;
}
if (instOf(request.body, 'FormData')) {
obj.body = ["XD_FD", request.body.entries];
reader = new FileReader();
reader.onload = function(e) {
obj.body = [
"XD_FD", {
file: e.target.result,
type: request.body.entries[0][1].type,
fileName: request.body.entries[0][1].name
}
];
return socket.emit("request", obj);
};
return reader.readAsArrayBuffer(request.body.entries[0][1]);
}
if (instOf(request.body, 'Uint8Array')) {
obj.body = request.body;
}
if (request.withCredentials) {
obj.credentials = document.cookie;
}
socket.emit("request", obj);
});
};
Expand Down Expand Up @@ -557,7 +568,7 @@ initSlave = function() {
return;
}
socket.once("request", function(req) {
var args, fd, k, p, v, xhr, _i, _len, _ref, _ref1;
var args, blob, body, fd, k, p, v, xhr, _i, _len, _ref;
log("request: " + req.method + " " + req.url);
p = parseUrl(req.url);
if (!(p && pathRegex.test(p.path))) {
Expand Down Expand Up @@ -609,10 +620,13 @@ initSlave = function() {
xhr.setRequestHeader(k, v);
}
if (req.body instanceof Array && req.body[0] === "XD_FD") {
blob = new Blob([req.body[1].file], {
type: req.body[1].type
});
body = [["files[]", blob, req.body[1].fileName]];
fd = new xhook.FormData();
_ref1 = req.body[1];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
args = _ref1[_i];
for (_i = 0, _len = body.length; _i < _len; _i++) {
args = body[_i];
fd.append.apply(fd, args);
}
req.body = fd;
Expand Down
Loading