@@ -27,7 +27,7 @@ public class MockResponseConfiguration
2727 public bool BlockUnmockedRequests { get ; set ; } = false ;
2828
2929 [ JsonPropertyName ( "$schema" ) ]
30- public string Schema { get ; set ; } = "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.16.1 /mockresponseplugin.schema.json" ;
30+ public string Schema { get ; set ; } = "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.17.0 /mockresponseplugin.schema.json" ;
3131 public IEnumerable < MockResponse > Mocks { get ; set ; } = Array . Empty < MockResponse > ( ) ;
3232}
3333
@@ -159,7 +159,9 @@ _configuration.Mocks is null ||
159159 if ( mockResponse . Request is null ) return false ;
160160
161161 if ( mockResponse . Request . Method != request . Method ) return false ;
162- if ( mockResponse . Request . Url == request . Url && IsNthRequest ( mockResponse ) )
162+ if ( mockResponse . Request . Url == request . Url &&
163+ HasMatchingBody ( mockResponse , request ) &&
164+ IsNthRequest ( mockResponse ) )
163165 {
164166 return true ;
165167 }
@@ -173,7 +175,9 @@ _configuration.Mocks is null ||
173175
174176 //turn mock URL with wildcard into a regex and match against the request URL
175177 var mockResponseUrlRegex = Regex . Escape ( mockResponse . Request . Url ) . Replace ( "\\ *" , ".*" ) ;
176- return Regex . IsMatch ( request . Url , $ "^{ mockResponseUrlRegex } $") && IsNthRequest ( mockResponse ) ;
178+ return Regex . IsMatch ( request . Url , $ "^{ mockResponseUrlRegex } $") &&
179+ HasMatchingBody ( mockResponse , request ) &&
180+ IsNthRequest ( mockResponse ) ;
177181 } ) ;
178182
179183 if ( mockResponse is not null && mockResponse . Request is not null )
@@ -188,6 +192,30 @@ _configuration.Mocks is null ||
188192 return mockResponse ;
189193 }
190194
195+ private bool HasMatchingBody ( MockResponse mockResponse , Request request )
196+ {
197+ if ( request . Method == "GET" )
198+ {
199+ // GET requests don't have a body so we can't match on it
200+ return true ;
201+ }
202+
203+ if ( mockResponse . Request ? . BodyFragment is null )
204+ {
205+ // no body fragment to match on
206+ return true ;
207+ }
208+
209+ if ( ! request . HasBody || string . IsNullOrEmpty ( request . BodyString ) )
210+ {
211+ // mock defines a body fragment but the request has no body
212+ // so it can't match
213+ return false ;
214+ }
215+
216+ return request . BodyString . Contains ( mockResponse . Request . BodyFragment , StringComparison . OrdinalIgnoreCase ) ;
217+ }
218+
191219 private bool IsNthRequest ( MockResponse mockResponse )
192220 {
193221 if ( mockResponse . Request is null || mockResponse . Request . Nth is null )
0 commit comments