mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
add 'arraybuffer' responseType to XHR
This commit is contained in:
@@ -125,6 +125,26 @@
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id=xhr6>
|
||||||
|
const req6 = new XMLHttpRequest()
|
||||||
|
testing.async(async (restore) => {
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
req6.onload = resolve;
|
||||||
|
req6.open('GET', 'http://127.0.0.1:9582/xhr/binary')
|
||||||
|
req6.responseType ='arraybuffer'
|
||||||
|
req6.send()
|
||||||
|
});
|
||||||
|
|
||||||
|
restore();
|
||||||
|
testing.expectEqual(200, req6.status);
|
||||||
|
testing.expectEqual('OK', req6.statusText);
|
||||||
|
testing.expectEqual(7, req6.response.byteLength);
|
||||||
|
testing.expectEqual([0, 0, 1, 2, 0, 0, 9], new Int32Array(req6.response));
|
||||||
|
testing.expectEqual('', typeof req6.response);
|
||||||
|
testing.expectEqual('arraybuffer', req6.responseType);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<script id=xhr_redirect>
|
<script id=xhr_redirect>
|
||||||
testing.async(async (restore) => {
|
testing.async(async (restore) => {
|
||||||
const req = new XMLHttpRequest();
|
const req = new XMLHttpRequest();
|
||||||
|
|||||||
@@ -69,12 +69,14 @@ const Response = union(ResponseType) {
|
|||||||
text: []const u8,
|
text: []const u8,
|
||||||
json: js.Value.Global,
|
json: js.Value.Global,
|
||||||
document: *Node.Document,
|
document: *Node.Document,
|
||||||
|
arraybuffer: js.ArrayBuffer,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ResponseType = enum {
|
const ResponseType = enum {
|
||||||
text,
|
text,
|
||||||
json,
|
json,
|
||||||
document,
|
document,
|
||||||
|
arraybuffer,
|
||||||
// TODO: other types to support
|
// TODO: other types to support
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -302,6 +304,7 @@ pub fn getResponse(self: *XMLHttpRequest, page: *Page) !?Response {
|
|||||||
try page.parseHtmlAsChildren(document.asNode(), data);
|
try page.parseHtmlAsChildren(document.asNode(), data);
|
||||||
break :blk .{ .document = document };
|
break :blk .{ .document = document };
|
||||||
},
|
},
|
||||||
|
.arraybuffer => .{ .arraybuffer = .{ .values = data } },
|
||||||
};
|
};
|
||||||
|
|
||||||
self._response = res;
|
self._response = res;
|
||||||
|
|||||||
@@ -558,6 +558,14 @@ fn testHTTPHandler(req: *std.http.Server.Request) !void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (std.mem.eql(u8, path, "/xhr/binary")) {
|
||||||
|
return req.respond(&.{ 0, 0, 1, 2, 0, 0, 9 }, .{
|
||||||
|
.extra_headers = &.{
|
||||||
|
.{ .name = "Content-Type", .value = "application/octet-stream" },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (std.mem.startsWith(u8, path, "/src/browser/tests/")) {
|
if (std.mem.startsWith(u8, path, "/src/browser/tests/")) {
|
||||||
// strip off leading / so that it's relative to CWD
|
// strip off leading / so that it's relative to CWD
|
||||||
return TestHTTPServer.sendFile(req, path[1..]);
|
return TestHTTPServer.sendFile(req, path[1..]);
|
||||||
|
|||||||
Reference in New Issue
Block a user