Skip to content

Commit

Permalink
fix: drop RequestWithCredentials internal (#329)
Browse files Browse the repository at this point in the history
- Follow-up to remix-run/web-std-io#21
- Related to mswjs/msw#1436
  • Loading branch information
kettanaito authored Jan 11, 2023
1 parent 3c0b5ec commit 5e1efa6
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 67 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"dependencies": {
"@open-draft/until": "^1.0.3",
"@remix-run/web-fetch": "^4.3.1",
"@remix-run/web-fetch": "^4.3.2",
"@types/debug": "^4.1.7",
"debug": "^4.3.3",
"headers-polyfill": "^3.1.0",
Expand Down
5 changes: 2 additions & 3 deletions src/RemoteHttpInterceptor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { ChildProcess } from 'child_process'
import { Response } from '@remix-run/web-fetch'
import { Request, Response } from '@remix-run/web-fetch'
import { Headers, HeadersObject, headersToObject } from 'headers-polyfill'
import { HttpRequestEventMap } from './glossary'
import { Interceptor } from './Interceptor'
import { BatchInterceptor } from './BatchInterceptor'
import { ClientRequestInterceptor } from './interceptors/ClientRequest'
import { XMLHttpRequestInterceptor } from './interceptors/XMLHttpRequest'
import { toInteractiveRequest } from './utils/toInteractiveRequest'
import { RequestWithCredentials } from './utils/RequestWithCredentials'

export interface SerializedRequest {
id: string
Expand Down Expand Up @@ -159,7 +158,7 @@ export class RemoteHttpResolver extends Interceptor<HttpRequestEventMap> {
) as RevivedRequest
log('parsed intercepted request', requestJson)

const capturedRequest = new RequestWithCredentials(requestJson.url, {
const capturedRequest = new Request(requestJson.url, {
method: requestJson.method,
headers: new Headers(requestJson.headers),
credentials: requestJson.credentials,
Expand Down
5 changes: 2 additions & 3 deletions src/interceptors/ClientRequest/utils/createRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Request } from '@remix-run/web-fetch'
import { Request } from '@remix-run/web-fetch'
import { Headers } from 'headers-polyfill'
import { RequestWithCredentials } from '../../../utils/RequestWithCredentials'
import type { NodeClientRequest } from '../NodeClientRequest'

/**
Expand All @@ -23,7 +22,7 @@ export function createRequest(clientRequest: NodeClientRequest): Request {
}
}

return new RequestWithCredentials(clientRequest.url, {
return new Request(clientRequest.url, {
method: clientRequest.method || 'GET',
headers,
credentials: 'same-origin',
Expand Down
4 changes: 2 additions & 2 deletions src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import type { Debugger } from 'debug'
import { until } from '@open-draft/until'
import { Request } from '@remix-run/web-fetch'
import { Headers, stringToHeaders, headersToString } from 'headers-polyfill'
import { parseJson } from '../../utils/parseJson'
import { createEvent } from './utils/createEvent'
Expand All @@ -17,7 +18,6 @@ import { createResponse } from './utils/createResponse'
import { concatArrayBuffer } from './utils/concatArrayBuffer'
import { toInteractiveRequest } from '../../utils/toInteractiveRequest'
import { uuidv4 } from '../../utils/uuid'
import { RequestWithCredentials } from '../../utils/RequestWithCredentials'
import { isDomParserSupportedType } from './utils/isDomParserSupportedType'

type XMLHttpRequestEventHandler = (
Expand Down Expand Up @@ -240,7 +240,7 @@ export const createXMLHttpRequestOverride = (

// Create an intercepted request instance exposed to the request intercepting middleware.
const requestId = uuidv4()
const capturedRequest = new RequestWithCredentials(url, {
const capturedRequest = new Request(url, {
method: this.method,
headers: this._requestHeaders,
credentials: this.withCredentials ? 'include' : 'omit',
Expand Down
27 changes: 0 additions & 27 deletions src/utils/RequestWithCredentials.test.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/utils/RequestWithCredentials.ts

This file was deleted.

5 changes: 2 additions & 3 deletions test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import https from 'https'
import http, { ClientRequest, IncomingMessage, RequestOptions } from 'http'
import nodeFetch, { Response, RequestInfo, RequestInit } from 'node-fetch'
import { objectToHeaders } from 'headers-polyfill'
import type { Request } from '@remix-run/web-fetch'
import { Request } from '@remix-run/web-fetch'
import { Page, ScenarioApi } from 'page-with'
import { getRequestOptionsByUrl } from '../src/utils/getRequestOptionsByUrl'
import { getIncomingMessageBody } from '../src/interceptors/ClientRequest/utils/getIncomingMessageBody'
import { SerializedRequest } from '../src/RemoteHttpInterceptor'
import { RequestWithCredentials } from '../src/utils/RequestWithCredentials'

export interface PromisifiedResponse {
req: ClientRequest
Expand Down Expand Up @@ -214,7 +213,7 @@ export async function extractRequestFromPage(page: Page): Promise<Request> {
})
})

const request = new RequestWithCredentials(requestJson.url, {
const request = new Request(requestJson.url, {
method: requestJson.method,
headers: objectToHeaders(requestJson.headers),
credentials: requestJson.credentials,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,10 @@
"@remix-run/web-stream" "^1.0.0"
web-encoding "1.1.5"

"@remix-run/web-fetch@^4.3.1":
version "4.3.1"
resolved "https://registry.yarnpkg.com/@remix-run/web-fetch/-/web-fetch-4.3.1.tgz#afc88e133bed1a6aecb9d09b1b02127fc844da47"
integrity sha512-TOpuJo3jI7/qJAY0yTnvNJRQl4hlWAOHUHYKAbEddcLFLydv+0/WGT6OaIurJKsBFJJTjooe3FbKiP74sUIB/g==
"@remix-run/web-fetch@^4.3.2":
version "4.3.2"
resolved "https://registry.yarnpkg.com/@remix-run/web-fetch/-/web-fetch-4.3.2.tgz#193758bb7a301535540f0e3a86c743283f81cf56"
integrity sha512-aRNaaa0Fhyegv/GkJ/qsxMhXvyWGjPNgCKrStCvAvV1XXphntZI0nQO/Fl02LIQg3cGL8lDiOXOS1gzqDOlG5w==
dependencies:
"@remix-run/web-blob" "^3.0.4"
"@remix-run/web-form-data" "^3.0.3"
Expand Down

0 comments on commit 5e1efa6

Please sign in to comment.