@@ -227,19 +227,18 @@ Interceptor.prototype.match = function match(options, body, hostNameOnly) {
227227 body = this . scope . transformRequestBodyFunction ( body , this . _requestBody )
228228 }
229229
230- const checkHeaders = function ( header ) {
231- if ( _ . isFunction ( header . value ) ) {
232- return header . value ( options . getHeader ( header . name ) )
230+ const requestMatchesFilter = ( { name, value : predicate } ) => {
231+ const headerValue = options . getHeader ( name )
232+ if ( typeof predicate === 'function' ) {
233+ return predicate ( headerValue )
234+ } else {
235+ return common . matchStringOrRegexp ( headerValue , predicate )
233236 }
234- return common . matchStringOrRegexp (
235- options . getHeader ( header . name ) ,
236- header . value
237- )
238237 }
239238
240239 if (
241- ! this . scope . matchHeaders . every ( checkHeaders ) ||
242- ! this . interceptorMatchHeaders . every ( checkHeaders )
240+ ! this . scope . matchHeaders . every ( requestMatchesFilter ) ||
241+ ! this . interceptorMatchHeaders . every ( requestMatchesFilter )
243242 ) {
244243 this . scope . logger ( "headers don't match" )
245244 return false
@@ -375,9 +374,11 @@ Interceptor.prototype.match = function match(options, body, hostNameOnly) {
375374 return matches
376375}
377376
378- Interceptor . prototype . matchIndependentOfBody = function matchIndependentOfBody (
379- options
380- ) {
377+ /**
378+ * Return true when the interceptor's method, protocol, host, port, and path
379+ * match the provided options.
380+ */
381+ Interceptor . prototype . matchAddress = function matchAddress ( options ) {
381382 const isRegex = _ . isRegExp ( this . path )
382383 const isRegexBasePath = _ . isRegExp ( this . scope . basePath )
383384
@@ -393,21 +394,6 @@ Interceptor.prototype.matchIndependentOfBody = function matchIndependentOfBody(
393394 if ( this . scope . transformPathFunction ) {
394395 path = this . scope . transformPathFunction ( path )
395396 }
396-
397- const checkHeaders = function ( header ) {
398- return (
399- options . getHeader &&
400- common . matchStringOrRegexp ( options . getHeader ( header . name ) , header . value )
401- )
402- }
403-
404- if (
405- ! this . scope . matchHeaders . every ( checkHeaders ) ||
406- ! this . interceptorMatchHeaders . every ( checkHeaders )
407- ) {
408- return false
409- }
410-
411397 const comparisonKey = isRegex ? this . __nock_scopeKey : this . _key
412398 const matchKey = `${ method } ${ proto } ://${ options . host } ${ path } `
413399
0 commit comments