@@ -98,7 +98,7 @@ public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, str
9898 /// Determines whether a specific header is set on a request.
9999 /// </summary>
100100 /// <remarks>This method only checks headers in <see cref="System.Net.Http.Headers.HttpRequestHeaders"/></remarks>
101- /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct method on.</param>
101+ /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the request header on.</param>
102102 /// <param name="headerName">The name of the header to locate on the request.</param>
103103 /// <returns>true when the request contains a header with the specified name; otherwise, false.</returns>
104104 public static bool HasRequestHeader ( this HttpRequestMessage httpRequestMessage , string headerName )
@@ -120,7 +120,7 @@ public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage,
120120 /// Determines whether a specific header with a specific value is set on a request.
121121 /// </summary>
122122 /// <remarks>This method only checks headers in <see cref="System.Net.Http.Headers.HttpRequestHeaders"/></remarks>
123- /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct method on.</param>
123+ /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the request header on.</param>
124124 /// <param name="headerName">The name of the header to locate on the request.</param>
125125 /// <param name="headerValue">The value the header should have. Wildcard is supported.</param>
126126 /// <returns>true when the request contains a header with the specified name and value; otherwise, false.</returns>
@@ -148,8 +148,8 @@ public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage,
148148 /// Determines whether a specific header is set on a request.
149149 /// </summary>
150150 /// <remarks>This method only checks headers in <see cref="System.Net.Http.Headers.HttpContentHeaders"/></remarks>
151- /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct method on.</param>
152- /// <param name="headerName">The name of the header to locate on the request.</param>
151+ /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the content header on.</param>
152+ /// <param name="headerName">The name of the header to locate on the request content .</param>
153153 /// <returns>true when the request contains a header with the specified name; otherwise, false.</returns>
154154 public static bool HasContentHeader ( this HttpRequestMessage httpRequestMessage , string headerName )
155155 {
@@ -175,8 +175,8 @@ public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage,
175175 /// Determines whether a specific header with a specific value is set on a request.
176176 /// </summary>
177177 /// <remarks>This method only checks headers in <see cref="System.Net.Http.Headers.HttpContentHeaders"/></remarks>
178- /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct method on.</param>
179- /// <param name="headerName">The name of the header to locate on the request.</param>
178+ /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the content header on.</param>
179+ /// <param name="headerName">The name of the header to locate on the request content .</param>
180180 /// <param name="headerValue">The value the header should have. Wildcard is supported.</param>
181181 /// <returns>true when the request contains a header with the specified name and value; otherwise, false.</returns>
182182 public static bool HasContentHeader ( this HttpRequestMessage httpRequestMessage , string headerName , string headerValue )
@@ -223,8 +223,8 @@ private static bool HasHeader(this HttpHeaders headers, string headerName, strin
223223 /// <summary>
224224 /// Determines whether the request uri matches a pattern.
225225 /// </summary>
226- /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct method on.</param>
227- /// <param name="pattern">A pattern to match with the request uri, support * as wildcards.</param>
226+ /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct uri on.</param>
227+ /// <param name="pattern">A pattern to match with the request uri, supports * as wildcards.</param>
228228 /// <returns>true when the request uri matches the pattern; otherwise, false.</returns>
229229 public static bool HasMatchingUri ( this HttpRequestMessage httpRequestMessage , string pattern )
230230 {
@@ -242,6 +242,39 @@ public static bool HasMatchingUri(this HttpRequestMessage httpRequestMessage, st
242242 } ;
243243 }
244244
245+ /// <summary>
246+ /// Determines whether the request content matches a string pattern.
247+ /// </summary>
248+ /// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct content on.</param>
249+ /// <param name="pattern">A pattern to match the request content, supports * as wildcards.</param>
250+ /// <returns>true when the request content matches the pattern; otherwise, false.</returns>
251+ public static bool HasContent ( this HttpRequestMessage httpRequestMessage , string pattern )
252+ {
253+ if ( httpRequestMessage == null )
254+ {
255+ throw new ArgumentNullException ( nameof ( httpRequestMessage ) ) ;
256+ }
257+
258+ if ( pattern == null )
259+ {
260+ throw new ArgumentNullException ( nameof ( pattern ) ) ;
261+ }
262+
263+ if ( httpRequestMessage . Content == null )
264+ {
265+ return false ;
266+ }
267+
268+ var stringContent = httpRequestMessage . Content . ReadAsStringAsync ( ) . Result ;
269+
270+ return pattern switch
271+ {
272+ "" => stringContent == pattern ,
273+ "*" => true ,
274+ _ => Matches ( stringContent , pattern ) ,
275+ } ;
276+ }
277+
245278 private static bool Matches ( string value , string pattern )
246279 {
247280 var regex = Regex . Escape ( pattern ) . Replace ( "\\ *" , "(.*)" ) ;
0 commit comments