@@ -194,9 +194,15 @@ public extension HTTPRoute {
194194 fatalError ( )
195195 }
196196
197+ #if compiler(>=6.2)
198+ nonisolated ( nonsending) static func ~= ( route: HTTPRoute , request: HTTPRequest ) async -> Bool {
199+ await route. patternMatch ( request: request)
200+ }
201+ #else
197202 static func ~= ( route: HTTPRoute , request: HTTPRequest ) async -> Bool {
198203 await route. patternMatch ( request: request)
199204 }
205+ #endif
200206}
201207
202208private extension HTTPRoute {
@@ -224,13 +230,23 @@ private extension HTTPRoute {
224230 return nil
225231 }
226232
233+ #if compiler(>=6.2)
234+ nonisolated ( nonsending) func patternMatch( request: HTTPRequest ) async -> Bool {
235+ guard patternMatch ( query: request. query) ,
236+ patternMatch ( headers: request. headers) ,
237+ await patternMatch ( body: request. bodySequence) else { return false }
238+
239+ return patternMatch ( method: request. method, path: request. path)
240+ }
241+ #else
227242 func patternMatch( request: HTTPRequest ) async -> Bool {
228243 guard patternMatch ( query: request. query) ,
229244 patternMatch ( headers: request. headers) ,
230245 await patternMatch ( body: request. bodySequence) else { return false }
231246
232247 return patternMatch ( method: request. method, path: request. path)
233248 }
249+ #endif
234250
235251 func patternMatch( method: HTTPMethod , path: String ) -> Bool {
236252 guard self . methods. contains ( method) else {
@@ -265,6 +281,22 @@ private extension HTTPRoute {
265281 }
266282 }
267283
284+ #if compiler(>=6.2)
285+ nonisolated ( nonsending) func patternMatch( body request: HTTPBodySequence ) async -> Bool {
286+ guard let body = body else { return true }
287+
288+ guard request. canReplay else {
289+ // body is large and can only be iterated one-time only so should not match it
290+ return false
291+ }
292+
293+ do {
294+ return try await body. evaluate ( request. get ( ) )
295+ } catch {
296+ return false
297+ }
298+ }
299+ #else
268300 func patternMatch( body request: HTTPBodySequence ) async -> Bool {
269301 guard let body = body else { return true }
270302
@@ -279,6 +311,7 @@ private extension HTTPRoute {
279311 return false
280312 }
281313 }
314+ #endif
282315
283316 static func components( for target: String ) -> (
284317 methods: Set < HTTPMethod > ,
0 commit comments