@@ -10,6 +10,9 @@ namespace Kestrel;
10
10
11
11
public sealed partial class BenchmarkApp : IHttpApplication < IFeatureCollection >
12
12
{
13
+ private const string TextPlainContentType = "text/plain" ;
14
+ private const string JsonContentTypeWithCharset = "application/json; charset=utf-8" ;
15
+
13
16
public IFeatureCollection CreateContext ( IFeatureCollection features ) => features ;
14
17
15
18
public Task ProcessRequestAsync ( IFeatureCollection features )
@@ -47,7 +50,7 @@ public void DisposeContext(IFeatureCollection features, Exception? exception) {
47
50
private static async Task Index ( IHttpResponseFeature res , IFeatureCollection features )
48
51
{
49
52
res . StatusCode = StatusCodes . Status200OK ;
50
- res . Headers . ContentType = "text/plain" ;
53
+ res . Headers . ContentType = TextPlainContentType ;
51
54
res . Headers . ContentLength = IndexPayload . Length ;
52
55
53
56
var body = features . GetResponseBodyFeature ( ) ;
@@ -62,7 +65,7 @@ private static async Task Index(IHttpResponseFeature res, IFeatureCollection fea
62
65
private static async Task Plaintext ( IHttpResponseFeature res , IFeatureCollection features )
63
66
{
64
67
res . StatusCode = StatusCodes . Status200OK ;
65
- res . Headers . ContentType = "text/plain" ;
68
+ res . Headers . ContentType = TextPlainContentType ;
66
69
res . Headers . ContentLength = HelloWorldPayload . Length ;
67
70
68
71
var body = features . GetResponseBodyFeature ( ) ;
@@ -74,7 +77,7 @@ private static async Task Plaintext(IHttpResponseFeature res, IFeatureCollection
74
77
private static async Task JsonChunked ( IHttpResponseFeature res , IFeatureCollection features )
75
78
{
76
79
res . StatusCode = StatusCodes . Status200OK ;
77
- res . Headers . ContentType = "application/json; charset=utf-8" ;
80
+ res . Headers . ContentType = JsonContentTypeWithCharset ;
78
81
79
82
var body = features . GetResponseBodyFeature ( ) ;
80
83
await body . StartAsync ( ) ;
@@ -85,7 +88,7 @@ private static async Task JsonChunked(IHttpResponseFeature res, IFeatureCollecti
85
88
private static async Task JsonString ( IHttpResponseFeature res , IFeatureCollection features )
86
89
{
87
90
res . StatusCode = StatusCodes . Status200OK ;
88
- res . Headers . ContentType = "application/json; charset=utf-8" ;
91
+ res . Headers . ContentType = JsonContentTypeWithCharset ;
89
92
90
93
var message = JsonSerializer . Serialize ( new JsonMessage { message = "Hello, World!" } , SerializerContext . JsonMessage ) ;
91
94
res . Headers . ContentLength = Encoding . UTF8 . GetByteCount ( message ) ;
@@ -103,7 +106,7 @@ private static async Task JsonString(IHttpResponseFeature res, IFeatureCollectio
103
106
private static async Task JsonUtf8Bytes ( IHttpResponseFeature res , IFeatureCollection features )
104
107
{
105
108
res . StatusCode = StatusCodes . Status200OK ;
106
- res . Headers . ContentType = "application/json; charset=utf-8" ;
109
+ res . Headers . ContentType = JsonContentTypeWithCharset ;
107
110
108
111
var messageBytes = JsonSerializer . SerializeToUtf8Bytes ( new JsonMessage { message = "Hello, World!" } , SerializerContext . JsonMessage ) ;
109
112
res . Headers . ContentLength = messageBytes . Length ;
@@ -119,7 +122,7 @@ private static async Task JsonUtf8Bytes(IHttpResponseFeature res, IFeatureCollec
119
122
private static async Task Json ( IHttpResponseFeature res , IFeatureCollection features )
120
123
{
121
124
res . StatusCode = StatusCodes . Status200OK ;
122
- res . Headers . ContentType = "application/json; charset=utf-8" ;
125
+ res . Headers . ContentType = JsonContentTypeWithCharset ;
123
126
124
127
var messageSpan = JsonSerializeToUtf8Span ( new JsonMessage { message = "Hello, World!" } , SerializerContext . JsonMessage ) ;
125
128
res . Headers . ContentLength = messageSpan . Length ;
0 commit comments