Skip to content

Commit 0b07f92

Browse files
authored
レスポンス高速化 (#13)
* レスポンス高速化 #5 * fix
1 parent a72e6dc commit 0b07f92

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

SlackLineBridge/Controllers/WebhookController.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public WebhookController(
4545
}
4646

4747
[HttpPost("/slack")]
48-
public async Task<OkResult> Slack([FromForm]SlackData data)
48+
public async Task<OkResult> Slack([FromForm] SlackData data)
4949
{
5050
if (data.user_name == "slackbot") return Ok();
5151

@@ -123,7 +123,7 @@ public async Task<OkResult> Slack([FromForm]SlackData data)
123123
}
124124

125125
[HttpPost("/line")]
126-
public async Task<StatusCodeResult> Line()
126+
public async Task<StatusCodeResult> LineAsync()
127127
{
128128
if (!Request.Headers.ContainsKey("X-Line-Signature"))
129129
{
@@ -132,11 +132,23 @@ public async Task<StatusCodeResult> Line()
132132
return BadRequest();
133133
}
134134

135-
using var reader = new StreamReader(Request.Body);
136-
137-
_lineRequestQueue.Enqueue((Request.Headers["X-Line-Signature"], await reader.ReadToEndAsync(), Request.Host.ToString()));
135+
string json = null;
136+
string host = null;
137+
try
138+
{
139+
using var reader = new StreamReader(Request.Body);
140+
json = await reader.ReadToEndAsync();
141+
host = Request.Host.ToString();
142+
return Ok();
143+
}
144+
finally
145+
{
146+
Response.OnCompleted(async () =>
147+
{
148+
_lineRequestQueue.Enqueue((Request.Headers["X-Line-Signature"], json, host));
149+
});
150+
}
138151

139-
return Ok();
140152
}
141153

142154
[HttpGet("/health")]

0 commit comments

Comments
 (0)