Skip to content

Commit 046ad1a

Browse files
committed
Optimization: Response Status Word
1 parent f6c8281 commit 046ad1a

File tree

1 file changed

+10
-6
lines changed
  • frameworks/CSharp/touchsocket/src/TouchSocketHttp

1 file changed

+10
-6
lines changed

frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ protected override MyHttpSessionClient NewClient()
4343

4444
sealed class MyHttpSessionClient : HttpSessionClient
4545
{
46-
HttpContent m_contentPlaintext = StringHttpContent.FromText("Hello, World!");
47-
HttpContent m_contentJson = StringHttpContent.FromJson("{\"Message\":\"Hello, World!\"}");
46+
private HttpContent m_contentPlaintext = StringHttpContent.FromText("Hello, World!");
47+
private HttpContent m_contentJson = StringHttpContent.FromJson("{\"Message\":\"Hello, World!\"}");
4848

4949
protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
5050
{
@@ -55,15 +55,19 @@ protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
5555
{
5656
case "/plaintext":
5757
{
58-
response.SetStatus(200, "success");
59-
response.SetContent(m_contentPlaintext);
58+
response.StatusCode = 200;
59+
response.StatusMessage = "success";
60+
response.Headers.Add(HttpHeaders.Server, HttpExtensions.HttpHeadersServer);
61+
response.Content = m_contentPlaintext;
6062
await response.AnswerAsync().ConfigureAwait(false);
6163
}
6264
break;
6365
case "/json":
6466
{
65-
response.SetStatus(200, "success");
66-
response.SetContent(m_contentJson);
67+
response.StatusCode = 200;
68+
response.StatusMessage = "success";
69+
response.Headers.Add(HttpHeaders.Server, HttpExtensions.HttpHeadersServer);
70+
response.Content = m_contentJson;
6771
await response.AnswerAsync().ConfigureAwait(false);
6872
}
6973
break;

0 commit comments

Comments
 (0)