|
1 | 1 | import Dockerode from "dockerode"; |
2 | | -import { Agent } from "undici"; |
| 2 | +import { Agent, Dispatcher, request } from "undici"; |
3 | 3 | import { IntervalRetry, log } from "../common"; |
4 | 4 | import { getContainerRuntimeClient } from "../container-runtime"; |
5 | 5 | import { BoundPorts } from "../utils/bound-ports"; |
@@ -91,17 +91,18 @@ export class HttpWaitStrategy extends AbstractWaitStrategy { |
91 | 91 |
|
92 | 92 | if (containerStatus === exitStatus) { |
93 | 93 | containerExited = true; |
94 | | - |
95 | 94 | return; |
96 | 95 | } |
97 | 96 | } |
98 | 97 |
|
99 | | - return await fetch(url, { |
100 | | - method: this.method, |
101 | | - signal: AbortSignal.timeout(this.readTimeout), |
102 | | - headers: this.headers, |
103 | | - dispatcher: this.getAgent(), |
104 | | - }); |
| 98 | + return this.undiciResponseToFetchResponse( |
| 99 | + await request(url, { |
| 100 | + method: this.method, |
| 101 | + signal: AbortSignal.timeout(this.readTimeout), |
| 102 | + headers: this.headers, |
| 103 | + dispatcher: this.getAgent(), |
| 104 | + }) |
| 105 | + ); |
105 | 106 | } catch { |
106 | 107 | return undefined; |
107 | 108 | } |
@@ -163,6 +164,31 @@ export class HttpWaitStrategy extends AbstractWaitStrategy { |
163 | 164 | throw new Error(message); |
164 | 165 | } |
165 | 166 |
|
| 167 | + /** |
| 168 | + * Converts an undici response to a fetch response. |
| 169 | + * This is necessary because node's fetch does not support disabling SSL validation (https://github.com/orgs/nodejs/discussions/44038). |
| 170 | + * |
| 171 | + * @param undiciResponse The undici response to convert. |
| 172 | + * @returns The fetch response. |
| 173 | + */ |
| 174 | + private undiciResponseToFetchResponse(undiciResponse: Dispatcher.ResponseData): Response { |
| 175 | + const headers = new Headers(); |
| 176 | + for (const [key, value] of Object.entries(undiciResponse.headers)) { |
| 177 | + if (Array.isArray(value)) { |
| 178 | + for (const v of value) { |
| 179 | + headers.append(key, v); |
| 180 | + } |
| 181 | + } else if (value !== undefined) { |
| 182 | + headers.set(key, value); |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + return new Response(undiciResponse.body, { |
| 187 | + status: undiciResponse.statusCode, |
| 188 | + headers, |
| 189 | + }); |
| 190 | + } |
| 191 | + |
166 | 192 | private getAgent(): Agent | undefined { |
167 | 193 | if (this._allowInsecure) { |
168 | 194 | return new Agent({ |
|
0 commit comments