-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: log
ReadableStream
responses as text/json (#1622)
Co-authored-by: Guillaume Esquevin <[email protected]> Co-authored-by: Artem Zakharchenko <[email protected]>
- Loading branch information
1 parent
8e37d9c
commit 4c7e952
Showing
5 changed files
with
21 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { flattenHeadersObject, headersToObject } from 'headers-polyfill' | ||
import type { SerializedResponse } from '../../setupWorker/glossary' | ||
|
||
export function serializeResponse(source: Response): SerializedResponse<any> { | ||
export async function serializeResponse( | ||
response: Response, | ||
): Promise<SerializedResponse<string>> { | ||
return { | ||
status: source.status, | ||
statusText: source.statusText, | ||
headers: flattenHeadersObject(headersToObject(source.headers)), | ||
body: source.body, | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: flattenHeadersObject(headersToObject(response.headers)), | ||
// Serialize the response body to a string | ||
// so it's easier to process further down the chain in "prepareResponse" (browser-only) | ||
// and "parseBody" (ambiguous). | ||
body: await response.text(), | ||
} | ||
} |