-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.ts
More file actions
33 lines (31 loc) · 939 Bytes
/
create.ts
File metadata and controls
33 lines (31 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
// This module is browser compatible.
/** Create a new `Response`.
*
* If you create a new `Response` from an existing `Response`, any options you set
* in an options argument for the new response replace any corresponding options
* set in the original `Response`.
*
* @example
* ```ts
* import { createResponse } from "https://deno.land/x/response_utils@$VERSION/create.ts";
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
*
* declare const init: Response;
* const response = createResponse(init, { status: 201 });
*
* assertEquals(response.status, 201);
* ```
*/
export function createResponse(
input: Response,
init?: ResponseInit,
): Response {
init = {
headers: input.headers,
status: input.status,
statusText: input.statusText,
...init,
};
return new Response(input.body, init);
}