import { FetchResponse } from "@mswjs/interceptors";
import {
decorateResponse,
normalizeResponseInit
} from './utils/HttpResponse/decorators.mjs';
const bodyType = Symbol("bodyType");
class HttpResponse extends FetchResponse {
[bodyType] = null;
constructor(body, init) {
const responseInit = normalizeResponseInit(init);
super(body, responseInit);
decorateResponse(this, responseInit);
}
static error() {
return super.error();
}
/**
* Create a `Response` with a `Content-Type: "text/plain"` body.
* @example
* HttpResponse.text('hello world')
* HttpResponse.text('Error', { status: 500 })
*/
static text(body, init) {
const responseInit = normalizeResponseInit(init);
if (!responseInit.headers.has("Content-Type")) {
responseInit.headers.set("Content-Type", "text/plain");
}
if (!responseInit.headers.has("Content-Length")) {
responseInit.headers.set(
"Content-Length",
body ? new Blob([body]).size.toString() : "0"
);
}
return new HttpResponse(body, responseInit);
}
/**
* Create a `Response` with a `Content-Type: "application/json"` body.
* @example
* HttpResponse.json({ firstName: 'John' })
* HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
*/
static json(body, init) {
const responseInit = normalizeResponseInit(init);
if (!responseInit.headers.has("Content-Type")) {
responseInit.headers.set("Content-Type", "application/json");
}
const responseText = JSON.stringify(body);
if (!responseInit.headers.has("Content-Length")) {
responseInit.headers.set(
"Content-Length",
responseText ? new Blob([responseText]).size.toString() : "0"
);
}
return new HttpResponse(responseText, responseInit);
}
/**
* Create a `Response` with a `Content-Type: "application/xml"` body.
* @example
* HttpResponse.xml(`