@@ -128,6 +128,20 @@ function checkHeader(headers, headerName) {
128128 return null ;
129129}
130130
131+ /**
132+ * When SEND_PROXY_HEADER and SEND_PROXY_VALUE are set and we're checking the same header,
133+ * the proxy response must echo that value (e.g. X-ProxyMesh-IP).
134+ * @returns {string|null } Error message if expectation not met, null if OK or N/A.
135+ */
136+ function validateSentHeaderValue ( config , headerValue ) {
137+ if ( ! config . sendProxyHeader || ! config . sendProxyValue ) return null ;
138+ if ( config . proxyHeader . toLowerCase ( ) !== config . sendProxyHeader . toLowerCase ( ) ) return null ;
139+ const expected = String ( config . sendProxyValue ) . trim ( ) ;
140+ const actual = headerValue ? String ( headerValue ) . trim ( ) : '' ;
141+ if ( actual === expected ) return null ;
142+ return `Expected ${ config . proxyHeader } to equal ${ expected } (sent in request) but got ${ actual } ` ;
143+ }
144+
131145const AVAILABLE_TESTS = {
132146 async core ( config ) {
133147 try {
@@ -159,7 +173,10 @@ const AVAILABLE_TESTS = {
159173 ? checkHeader ( capturedHeaders , config . proxyHeader )
160174 : null ;
161175
162- if ( headerValue ) {
176+ const sentErr = validateSentHeaderValue ( config , headerValue ) ;
177+ if ( sentErr ) {
178+ resolve ( new TestResult ( 'core' , false , null , sentErr , res . statusCode ) ) ;
179+ } else if ( headerValue ) {
163180 resolve ( new TestResult ( 'core' , true , headerValue , null , res . statusCode ) ) ;
164181 } else {
165182 resolve ( new TestResult ( 'core' , false , null ,
@@ -194,6 +211,8 @@ const AVAILABLE_TESTS = {
194211 } ) ;
195212 const headerValue = checkHeader ( response . headers , config . proxyHeader ) ;
196213
214+ const sentErr = validateSentHeaderValue ( config , headerValue ) ;
215+ if ( sentErr ) return new TestResult ( 'axios' , false , null , sentErr ) ;
197216 if ( headerValue ) {
198217 return new TestResult ( 'axios' , true , headerValue , null , response . status ) ;
199218 }
@@ -216,6 +235,8 @@ const AVAILABLE_TESTS = {
216235
217236 const headerValue = checkHeader ( response . proxyHeaders , config . proxyHeader ) ;
218237
238+ const sentErr = validateSentHeaderValue ( config , headerValue ) ;
239+ if ( sentErr ) return new TestResult ( 'node-fetch' , false , null , sentErr ) ;
219240 if ( headerValue ) {
220241 return new TestResult ( 'node-fetch' , true , headerValue , null , response . status ) ;
221242 }
@@ -240,6 +261,8 @@ const AVAILABLE_TESTS = {
240261 const response = await client ( config . testUrl ) ;
241262 const headerValue = checkHeader ( response . headers , config . proxyHeader ) ;
242263
264+ const sentErr = validateSentHeaderValue ( config , headerValue ) ;
265+ if ( sentErr ) return new TestResult ( 'got' , false , null , sentErr ) ;
243266 if ( headerValue ) {
244267 return new TestResult ( 'got' , true , headerValue , null , response . statusCode ) ;
245268 }
@@ -262,6 +285,8 @@ const AVAILABLE_TESTS = {
262285
263286 const headerValue = checkHeader ( proxyHeaders , config . proxyHeader ) ;
264287
288+ const sentErr = validateSentHeaderValue ( config , headerValue ) ;
289+ if ( sentErr ) return new TestResult ( 'undici' , false , null , sentErr ) ;
265290 if ( headerValue ) {
266291 return new TestResult ( 'undici' , true , headerValue , null , statusCode ) ;
267292 }
@@ -285,6 +310,8 @@ const AVAILABLE_TESTS = {
285310 const response = await client . get ( config . testUrl ) . ok ( ( ) => true ) ;
286311 const headerValue = checkHeader ( response . headers , config . proxyHeader ) ;
287312
313+ const sentErr = validateSentHeaderValue ( config , headerValue ) ;
314+ if ( sentErr ) return new TestResult ( 'superagent' , false , null , sentErr ) ;
288315 if ( headerValue ) {
289316 return new TestResult ( 'superagent' , true , headerValue , null , response . status ) ;
290317 }
0 commit comments