import { packResponse } from "https://deno.land/x/cav@0.2.0-alpha.7/serial.ts";
Serializes a new Response, which can then be deserialized back into the input
body using unpack()
. Any headers specified on the init options will
override the headers determined during serialization. The same applies for
status and statusText. The serializable input types can be extended with the
serializers option.
If the body is undefined
, a 204 Response is created. If the body is null
,
a 200 response is created with a zero-length body.
If the body extends BodyInit, it'll be passed through to the Response
constructor unmodified. During unpack()
, it'll be deserialized according to
the content-type set on the response headers, which can sometimes result in
asymmetric deserialization.
If the body is a File or Blob, it'll also be sent with a
"content-disposition: attachment" header. During unpack()
, it will be
deserialized back into a regular Blob or File, along with the file name if
there is one, regardless of the content-type.
If the body is any other type, it'll first be serialized as JSON using
serialize()
. The default serializers are extended to include Files and
Blobs; if a File or Blob exists on the serialized value, the response will be
sent as a specially formatted FormData instead of JSON. During unpack()
,
it'll be deserialized back into the original body
with all the Files and
Blobs back in the right place. Referential equality for Files and Blobs will
be preserved, so that duplicate Blobs only have 1 copy uploaded.