2929use function parse_url ;
3030use function str_contains ;
3131use function strtolower ;
32+ use function is_array ;
3233
3334/**
3435 *
@@ -68,14 +69,7 @@ public function request(RequestInterface $request, array $option = []): Response
6869 $ port = $ scheme === 'https ' ? 443 : 80 ;
6970 }
7071
71- if (!isset ($ option ['proxy ' ])) {
72- if ($ scheme === 'http ' && $ httpProxy = getenv ('http_proxy ' )) {
73- $ option ['proxy ' ] = $ httpProxy ;
74- } elseif ($ scheme === 'https ' && $ httpsProxy = getenv ('https_proxy ' )) {
75- $ option ['proxy ' ] = $ httpsProxy ;
76- }
77- }
78-
72+ $ proxy = $ this ->parseProxy ($ scheme , $ option ['proxy ' ] ?? null );
7973 $ capture = $ option ['capture ' ] ?? null ;
8074
8175 try {
@@ -84,7 +78,7 @@ public function request(RequestInterface $request, array $option = []): Response
8478 $ port ,
8579 $ scheme === 'https ' ,
8680 $ option ['timeout ' ] ?? 0 ,
87- $ option [ ' proxy ' ] ?? null
81+ $ proxy
8882 );
8983 } catch (Throwable $ exception ) {
9084 if ($ capture instanceof Capture) {
@@ -186,4 +180,29 @@ public function getConnectionPool(): ConnectionPool|null
186180 {
187181 return $ this ->connectionPool ;
188182 }
183+
184+ /**
185+ * @param string $scheme
186+ * @param mixed|null $proxy
187+ * @return mixed
188+ */
189+ private function parseProxy (string $ scheme , mixed $ proxy = null ): mixed
190+ {
191+ if (is_array ($ proxy )) {
192+ return $ proxy [$ scheme ] ?? null ;
193+ }
194+
195+ if ($ proxy ) {
196+ return $ proxy ;
197+ }
198+
199+ if ($ scheme === 'http ' && $ httpProxy = getenv ('http_proxy ' )) {
200+ return $ httpProxy ;
201+ }
202+ if ($ scheme === 'https ' && $ httpsProxy = getenv ('https_proxy ' )) {
203+ return $ httpsProxy ;
204+ }
205+
206+ return null ;
207+ }
189208}
0 commit comments