(env)
| 66 | }; |
| 67 | |
| 68 | const factory = (env) => { |
| 69 | const globalObject = |
| 70 | utils.global !== undefined && utils.global !== null |
| 71 | ? utils.global |
| 72 | : globalThis; |
| 73 | const { ReadableStream, TextEncoder } = globalObject; |
| 74 | |
| 75 | env = utils.merge.call( |
| 76 | { |
| 77 | skipUndefined: true, |
| 78 | }, |
| 79 | { |
| 80 | Request: globalObject.Request, |
| 81 | Response: globalObject.Response, |
| 82 | }, |
| 83 | env |
| 84 | ); |
| 85 | |
| 86 | const { fetch: envFetch, Request, Response } = env; |
| 87 | const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function'; |
| 88 | const isRequestSupported = isFunction(Request); |
| 89 | const isResponseSupported = isFunction(Response); |
| 90 | |
| 91 | if (!isFetchSupported) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream); |
| 96 | |
| 97 | const encodeText = |
| 98 | isFetchSupported && |
| 99 | (typeof TextEncoder === 'function' |
| 100 | ? ( |
| 101 | (encoder) => (str) => |
| 102 | encoder.encode(str) |
| 103 | )(new TextEncoder()) |
| 104 | : async (str) => new Uint8Array(await new Request(str).arrayBuffer())); |
| 105 | |
| 106 | const supportsRequestStream = |
| 107 | isRequestSupported && |
| 108 | isReadableStreamSupported && |
| 109 | test(() => { |
| 110 | let duplexAccessed = false; |
| 111 | |
| 112 | const request = new Request(platform.origin, { |
| 113 | body: new ReadableStream(), |
| 114 | method: 'POST', |
| 115 | get duplex() { |
| 116 | duplexAccessed = true; |
| 117 | return 'half'; |
| 118 | }, |
| 119 | }); |
| 120 | |
| 121 | const hasContentType = request.headers.has('Content-Type'); |
| 122 | |
| 123 | if (request.body != null) { |
| 124 | request.body.cancel(); |
| 125 | } |
no test coverage detected