@@ -20,22 +20,50 @@ public Task ProcessRequestAsync(IFeatureCollection features)
20
20
var req = features . GetRequestFeature ( ) ;
21
21
var res = features . GetResponseFeature ( ) ;
22
22
23
- if ( req . Method != "GET" )
23
+ //if (req.Method != "GET")
24
+ //{
25
+ // res.StatusCode = StatusCodes.Status405MethodNotAllowed;
26
+ // return Task.CompletedTask;
27
+ //}
28
+
29
+ var pathSpan = req . Path . AsSpan ( ) ;
30
+ if ( Paths . IsPath ( pathSpan , Paths . Plaintext ) )
24
31
{
25
- res . StatusCode = StatusCodes . Status405MethodNotAllowed ;
26
- return Task . CompletedTask ;
32
+ return Plaintext ( res , features ) ;
27
33
}
28
-
29
- return req . Path switch
34
+ else if ( Paths . IsPath ( pathSpan , Paths . Json ) )
35
+ {
36
+ return Json ( res , features ) ;
37
+ }
38
+ else if ( pathSpan . StartsWith ( "json-string" , StringComparison . OrdinalIgnoreCase ) )
39
+ {
40
+ return JsonString ( res , features ) ;
41
+ }
42
+ else if ( pathSpan . StartsWith ( "json-utf8bytes" , StringComparison . OrdinalIgnoreCase ) )
43
+ {
44
+ return JsonUtf8Bytes ( res , features ) ;
45
+ }
46
+ else if ( pathSpan . StartsWith ( "json-chunked" , StringComparison . OrdinalIgnoreCase ) )
30
47
{
31
- "/plaintext" => Plaintext ( res , features ) ,
32
- "/json" => Json ( res , features ) ,
33
- "/json-string" => JsonString ( res , features ) ,
34
- "/json-utf8bytes" => JsonUtf8Bytes ( res , features ) ,
35
- "/json-chunked" => JsonChunked ( res , features ) ,
36
- "/" => Index ( res , features ) ,
37
- _ => NotFound ( res , features ) ,
38
- } ;
48
+ return JsonChunked ( res , features ) ;
49
+ }
50
+ else if ( pathSpan . IsEmpty || pathSpan . Equals ( "/" , StringComparison . OrdinalIgnoreCase ) )
51
+ {
52
+ return Index ( res , features ) ;
53
+ }
54
+
55
+ return NotFound ( res , features ) ;
56
+
57
+ //return req.Path switch
58
+ //{
59
+ // "/plaintext" => Plaintext(res, features),
60
+ // "/json" => Json(res, features),
61
+ // "/json-string" => JsonString(res, features),
62
+ // "/json-utf8bytes" => JsonUtf8Bytes(res, features),
63
+ // "/json-chunked" => JsonChunked(res, features),
64
+ // "/" => Index(res, features),
65
+ // _ => NotFound(res, features),
66
+ //};
39
67
}
40
68
41
69
private static Task NotFound ( IHttpResponseFeature res , IFeatureCollection features )
@@ -168,4 +196,12 @@ private partial class JsonContext : JsonSerializerContext
168
196
{
169
197
170
198
}
199
+
200
+ private static class Paths
201
+ {
202
+ public static ReadOnlySpan < char > Plaintext => "/plaintext" ;
203
+ public static ReadOnlySpan < char > Json => "/json" ;
204
+
205
+ public static bool IsPath ( ReadOnlySpan < char > path , ReadOnlySpan < char > targetPath ) => path . SequenceEqual ( targetPath ) ;
206
+ }
171
207
}
0 commit comments