@opra/client
Version:
Opra Client package
24 lines (23 loc) • 800 B
JavaScript
/// <reference lib="dom" />
export class HttpResponse {
constructor(init) {
/**
* Returns true if response has body to be received
*/
this.hasBody = false;
this.headers =
init?.headers instanceof Headers
? init?.headers
: new Headers(init?.headers);
this.status = init?.status || 200;
this.statusText = init?.statusText || 'OK';
this.url = init?.url || null;
this.ok = this.status >= 200 && this.status < 300;
this.body = init?.body;
this.hasBody = init?.body != null || !!init?.hasBody;
this.contentType = (this.headers.get('content-type') || '').split(';')[0];
}
clone(update) {
return new HttpResponse({ ...this, ...update });
}
}