Skip to content

Commit

Permalink
レスポンス高速化 (#13)
Browse files Browse the repository at this point in the history
* レスポンス高速化 #5

* fix
  • Loading branch information
YDKK authored Oct 24, 2020
1 parent a72e6dc commit 0b07f92
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions SlackLineBridge/Controllers/WebhookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public WebhookController(
}

[HttpPost("/slack")]
public async Task<OkResult> Slack([FromForm]SlackData data)
public async Task<OkResult> Slack([FromForm] SlackData data)
{
if (data.user_name == "slackbot") return Ok();

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

[HttpPost("/line")]
public async Task<StatusCodeResult> Line()
public async Task<StatusCodeResult> LineAsync()
{
if (!Request.Headers.ContainsKey("X-Line-Signature"))
{
Expand All @@ -132,11 +132,23 @@ public async Task<StatusCodeResult> 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")]
Expand Down

0 comments on commit 0b07f92

Please sign in to comment.