MCPcopy
hub / github.com/mswjs/msw / html

Method html

src/core/HttpResponse.ts:175–196  ·  view source on GitHub ↗

* Create a `Response` with a `Content-Type: "text/html"` body. * @example * HttpResponse.html(` Jane Doe `) * HttpResponse.html(` Main text `, { status: 201 })

(
    body?: BodyType | null,
    init?: HttpResponseInit,
  )

Source from the content-addressed store, hash-verified

173 * HttpResponse.html(`<main id="abc-123">Main text</main>`, { status: 201 })
174 */
175 static html<BodyType extends string>(
176 body?: BodyType | null,
177 init?: HttpResponseInit,
178 ): HttpResponse<BodyType> {
179 const responseInit = normalizeResponseInit(init)
180 const hasExplicitContentType = responseInit.headers.has('Content-Type')
181
182 if (!hasExplicitContentType) {
183 responseInit.headers.set('Content-Type', 'text/html')
184 }
185
186 const response = new HttpResponse(body, responseInit)
187
188 if (!hasExplicitContentType) {
189 Object.defineProperty(response, kDefaultContentType, {
190 value: true,
191 enumerable: false,
192 })
193 }
194
195 return response as HttpResponse<BodyType>
196 }
197
198 /**
199 * Create a `Response` with an `ArrayBuffer` body.

Callers 4

body-html.mocks.tsFile · 0.80
defaultResolverFunction · 0.80

Calls 1

normalizeResponseInitFunction · 0.90

Tested by

no test coverage detected