Skip to content

Commit 3f7dec5

Browse files
committed
Use constants for content types
1 parent 7bead58 commit 3f7dec5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/BenchmarksApps/TechEmpower/Kestrel/BenchmarkApp.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ namespace Kestrel;
1010

1111
public sealed partial class BenchmarkApp : IHttpApplication<IFeatureCollection>
1212
{
13+
private const string TextPlainContentType = "text/plain";
14+
private const string JsonContentTypeWithCharset = "application/json; charset=utf-8";
15+
1316
public IFeatureCollection CreateContext(IFeatureCollection features) => features;
1417

1518
public Task ProcessRequestAsync(IFeatureCollection features)
@@ -47,7 +50,7 @@ public void DisposeContext(IFeatureCollection features, Exception? exception) {
4750
private static async Task Index(IHttpResponseFeature res, IFeatureCollection features)
4851
{
4952
res.StatusCode = StatusCodes.Status200OK;
50-
res.Headers.ContentType = "text/plain";
53+
res.Headers.ContentType = TextPlainContentType;
5154
res.Headers.ContentLength = IndexPayload.Length;
5255

5356
var body = features.GetResponseBodyFeature();
@@ -62,7 +65,7 @@ private static async Task Index(IHttpResponseFeature res, IFeatureCollection fea
6265
private static async Task Plaintext(IHttpResponseFeature res, IFeatureCollection features)
6366
{
6467
res.StatusCode = StatusCodes.Status200OK;
65-
res.Headers.ContentType = "text/plain";
68+
res.Headers.ContentType = TextPlainContentType;
6669
res.Headers.ContentLength = HelloWorldPayload.Length;
6770

6871
var body = features.GetResponseBodyFeature();
@@ -74,7 +77,7 @@ private static async Task Plaintext(IHttpResponseFeature res, IFeatureCollection
7477
private static async Task JsonChunked(IHttpResponseFeature res, IFeatureCollection features)
7578
{
7679
res.StatusCode = StatusCodes.Status200OK;
77-
res.Headers.ContentType = "application/json; charset=utf-8";
80+
res.Headers.ContentType = JsonContentTypeWithCharset;
7881

7982
var body = features.GetResponseBodyFeature();
8083
await body.StartAsync();
@@ -85,7 +88,7 @@ private static async Task JsonChunked(IHttpResponseFeature res, IFeatureCollecti
8588
private static async Task JsonString(IHttpResponseFeature res, IFeatureCollection features)
8689
{
8790
res.StatusCode = StatusCodes.Status200OK;
88-
res.Headers.ContentType = "application/json; charset=utf-8";
91+
res.Headers.ContentType = JsonContentTypeWithCharset;
8992

9093
var message = JsonSerializer.Serialize(new JsonMessage { message = "Hello, World!" }, SerializerContext.JsonMessage);
9194
res.Headers.ContentLength = Encoding.UTF8.GetByteCount(message);
@@ -103,7 +106,7 @@ private static async Task JsonString(IHttpResponseFeature res, IFeatureCollectio
103106
private static async Task JsonUtf8Bytes(IHttpResponseFeature res, IFeatureCollection features)
104107
{
105108
res.StatusCode = StatusCodes.Status200OK;
106-
res.Headers.ContentType = "application/json; charset=utf-8";
109+
res.Headers.ContentType = JsonContentTypeWithCharset;
107110

108111
var messageBytes = JsonSerializer.SerializeToUtf8Bytes(new JsonMessage { message = "Hello, World!" }, SerializerContext.JsonMessage);
109112
res.Headers.ContentLength = messageBytes.Length;
@@ -119,7 +122,7 @@ private static async Task JsonUtf8Bytes(IHttpResponseFeature res, IFeatureCollec
119122
private static async Task Json(IHttpResponseFeature res, IFeatureCollection features)
120123
{
121124
res.StatusCode = StatusCodes.Status200OK;
122-
res.Headers.ContentType = "application/json; charset=utf-8";
125+
res.Headers.ContentType = JsonContentTypeWithCharset;
123126

124127
var messageSpan = JsonSerializeToUtf8Span(new JsonMessage { message = "Hello, World!" }, SerializerContext.JsonMessage);
125128
res.Headers.ContentLength = messageSpan.Length;

0 commit comments

Comments
 (0)