@@ -223,6 +223,39 @@ describe("IP endpoint", () => {
223223 expect ( body . origin ) . to . equal ( '198.18.0.42' ) ;
224224 } ) ;
225225
226+ it ( "extracts origin from PROXY v1 header with TLS + HTTP/2" , async ( ) => {
227+ const socket = await createProxySocket ( proxyServerPort ,
228+ buildProxyV1Header ( '203.0.113.99' , '10.0.0.1' , 22222 , 443 )
229+ ) ;
230+
231+ // Wait for server to process PROXY header before TLS handshake
232+ await new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
233+
234+ const tlsSocket = tls . connect ( {
235+ socket,
236+ servername : 'localhost' ,
237+ rejectUnauthorized : false ,
238+ ALPNProtocols : [ 'h2' ]
239+ } ) ;
240+ await new Promise < void > ( ( resolve ) => tlsSocket . on ( 'secureConnect' , resolve ) ) ;
241+
242+ expect ( tlsSocket . alpnProtocol ) . to . equal ( 'h2' ) ;
243+
244+ const client = http2 . connect ( 'https://localhost' , {
245+ createConnection : ( ) => tlsSocket as any
246+ } ) ;
247+
248+ const request = client . request ( {
249+ ':path' : '/ip' ,
250+ ':method' : 'GET'
251+ } ) ;
252+
253+ const body : any = await streamConsumers . json ( request ) ;
254+ client . close ( ) ;
255+
256+ expect ( body . origin ) . to . equal ( '203.0.113.99' ) ;
257+ } ) ;
258+
226259 it ( "handles malformed PROXY v1 with invalid port gracefully" , async ( ) => {
227260 const socket = await createProxySocket ( proxyServerPort ,
228261 Buffer . from ( 'PROXY TCP4 1.2.3.4 5.6.7.8 99999 80\r\n' )
0 commit comments