From 0b07f9241837f73caf50dfa4b2f23f1bbdbb2cb1 Mon Sep 17 00:00:00 2001 From: YDKK Date: Sat, 24 Oct 2020 14:00:32 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AC=E3=82=B9=E3=83=9D=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E9=AB=98=E9=80=9F=E5=8C=96=20(#13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * レスポンス高速化 #5 * fix --- .../Controllers/WebhookController.cs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/SlackLineBridge/Controllers/WebhookController.cs b/SlackLineBridge/Controllers/WebhookController.cs index 82890a0..c17cc3d 100644 --- a/SlackLineBridge/Controllers/WebhookController.cs +++ b/SlackLineBridge/Controllers/WebhookController.cs @@ -45,7 +45,7 @@ public WebhookController( } [HttpPost("/slack")] - public async Task Slack([FromForm]SlackData data) + public async Task Slack([FromForm] SlackData data) { if (data.user_name == "slackbot") return Ok(); @@ -123,7 +123,7 @@ public async Task Slack([FromForm]SlackData data) } [HttpPost("/line")] - public async Task Line() + public async Task LineAsync() { if (!Request.Headers.ContainsKey("X-Line-Signature")) { @@ -132,11 +132,23 @@ public async Task Line() return BadRequest(); } - using var reader = new StreamReader(Request.Body); - - _lineRequestQueue.Enqueue((Request.Headers["X-Line-Signature"], await reader.ReadToEndAsync(), Request.Host.ToString())); + string json = null; + string host = null; + try + { + using var reader = new StreamReader(Request.Body); + json = await reader.ReadToEndAsync(); + host = Request.Host.ToString(); + return Ok(); + } + finally + { + Response.OnCompleted(async () => + { + _lineRequestQueue.Enqueue((Request.Headers["X-Line-Signature"], json, host)); + }); + } - return Ok(); } [HttpGet("/health")]