* Create a `Response` with an `ArrayBuffer` body. * @example * const buffer = new ArrayBuffer(3) * const view = new Uint8Array(buffer) * view.set([1, 2, 3]) * * HttpResponse.arrayBuffer(buffer)
(
body?: BodyType,
init?: HttpResponseInit,
)
| 205 | * HttpResponse.arrayBuffer(buffer) |
| 206 | */ |
| 207 | static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>( |
| 208 | body?: BodyType, |
| 209 | init?: HttpResponseInit, |
| 210 | ): HttpResponse<BodyType> { |
| 211 | const responseInit = normalizeResponseInit(init) |
| 212 | const hasExplicitContentType = responseInit.headers.has('Content-Type') |
| 213 | |
| 214 | if (!hasExplicitContentType) { |
| 215 | responseInit.headers.set('Content-Type', 'application/octet-stream') |
| 216 | } |
| 217 | |
| 218 | if (body && !responseInit.headers.has('Content-Length')) { |
| 219 | responseInit.headers.set('Content-Length', body.byteLength.toString()) |
| 220 | } |
| 221 | |
| 222 | const response = new HttpResponse(body, responseInit) |
| 223 | |
| 224 | if (!hasExplicitContentType) { |
| 225 | Object.defineProperty(response, kDefaultContentType, { |
| 226 | value: true, |
| 227 | enumerable: false, |
| 228 | }) |
| 229 | } |
| 230 | |
| 231 | return response as HttpResponse<BodyType> |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Create a `Response` with a `FormData` body. |
no test coverage detected