Skip to content

Commit

Permalink
Merge branch 'main' into feat/standard-api
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Jul 20, 2023
2 parents 59c3e52 + e87e00b commit 789327a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/utils/logging/serializeResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { flattenHeadersObject, headersToObject } from 'headers-polyfill'
import type { SerializedResponse } from '../../setupWorker/glossary'

export async function serializeResponse(
response: Response,
): Promise<SerializedResponse<string>> {
return {
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.clone().text(),
}
}
11 changes: 11 additions & 0 deletions src/utils/request/createResponseFromIsomorphicResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsomorphicResponse } from '@mswjs/interceptors'

export function createResponseFromIsomorphicResponse(
response: IsomorphicResponse,
): Response {
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: response.headers,
})
}

0 comments on commit 789327a

Please sign in to comment.