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

Method xml

src/core/HttpResponse.ts:146–167  ·  view source on GitHub ↗

* Create a `Response` with a `Content-Type: "application/xml"` body. * @example * HttpResponse.xml(` `) * HttpResponse.xml(` `, { status: 201 })

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

Source from the content-addressed store, hash-verified

144 * HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
145 */
146 static xml<BodyType extends string>(
147 body?: BodyType | null,
148 init?: HttpResponseInit,
149 ): HttpResponse<BodyType> {
150 const responseInit = normalizeResponseInit(init)
151 const hasExplicitContentType = responseInit.headers.has('Content-Type')
152
153 if (!hasExplicitContentType) {
154 responseInit.headers.set('Content-Type', 'text/xml')
155 }
156
157 const response = new HttpResponse(body, responseInit)
158
159 if (!hasExplicitContentType) {
160 Object.defineProperty(response, kDefaultContentType, {
161 value: true,
162 enumerable: false,
163 })
164 }
165
166 return response as HttpResponse<BodyType>
167 }
168
169 /**
170 * Create a `Response` with a `Content-Type: "text/html"` body.

Callers 4

body-xml.mocks.tsFile · 0.80
http.test-d.tsFile · 0.80

Calls 1

normalizeResponseInitFunction · 0.90

Tested by

no test coverage detected