| 96 | }: MockContextOptions<R> = {}, |
| 97 | ): RouterContext<R, P, S> { |
| 98 | function createMockRequest(): Request { |
| 99 | const headers = new Headers(requestHeaders); |
| 100 | return { |
| 101 | get source(): globalThis.Request | undefined { |
| 102 | return new globalThis.Request(new URL(path, "http://localhost/"), { |
| 103 | method, |
| 104 | headers, |
| 105 | }); |
| 106 | }, |
| 107 | accepts(...types: string[]) { |
| 108 | if (!headers.has("Accept")) { |
| 109 | return; |
| 110 | } |
| 111 | if (types.length) { |
| 112 | return accepts({ headers }, ...types); |
| 113 | } |
| 114 | return accepts({ headers }); |
| 115 | }, |
| 116 | acceptsEncodings() { |
| 117 | return mockContextState.encodingsAccepted; |
| 118 | }, |
| 119 | headers, |
| 120 | ip, |
| 121 | method, |
| 122 | path, |
| 123 | search: undefined, |
| 124 | searchParams: new URLSearchParams(), |
| 125 | url: new URL(path, "http://localhost/"), |
| 126 | hasBody: !!body, |
| 127 | body: body ? new Body({ headers, getBody: () => body }) : undefined, |
| 128 | } as any; |
| 129 | } |
| 130 | |
| 131 | const request = createMockRequest(); |
| 132 | const response = new Response(request); |