@opra/client
Version:
Opra Client package
52 lines (51 loc) • 1.41 kB
JavaScript
/// <reference lib="dom" />
export class HttpResponse {
/**
* Contains the Headers object associated with the response.
*/
headers;
/**
* Contains a Boolean stating whether the response was successful (status in the range 200-299) or not.
*/
ok;
/**
* Contains the HTTP status codes of the response
*/
status;
/**
* Contains the status message corresponding to the HTTP status code in status property
*/
statusText;
/**
* Contains the URL of the response
*/
url;
/**
* Body contents
*/
body;
/**
* Content-Type header value without encoding part
*/
contentType;
/**
* Returns true if response has body to be received
*/
hasBody = false;
constructor(init) {
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 });
}
}