Ivan Daniluk 6a096607cf Add FetchAPI support and fix loop race [upd] #289 (#293)
This PR adds Fetch API and fixes #289 by using concurrency safe Otto VM wrapper wherever it's possible. This involves new package geth/jail/vm that is used by jail and by our forked ottoext/{fetch/timers/loop} packages.

It also adds more tests that are supposed to be run with --race flag of go test.
2017-09-08 14:55:17 +03:00

24 lines
515 B
JavaScript

const Headers = require('./headers');
export default class Response {
bodyUsed = true;
_body = null;
constructor(body, {status=200, statusText='OK', headers={}}={}) {
this.headers = new Headers(headers);
this.ok = status >= 200 && status < 300;
this.status = status;
this.statusText = statusText;
this.type = this.headers.get('content-type');
}
text() {
return new Promise(resolve => resolve(this._body));
}
json() {
return this.text().then(d => JSON.parse(d));
}
}