Skip to content

Instantly share code, notes, and snippets.

@dbarkol
Created January 20, 2020 19:25
Show Gist options
  • Save dbarkol/78ab19872e272988465c5209cd294226 to your computer and use it in GitHub Desktop.
Save dbarkol/78ab19872e272988465c5209cd294226 to your computer and use it in GitHub Desktop.
Validation response for CloudEvents in ASP.NET Core Web API
[HttpOptions]
public async Task<IActionResult> Options()
{
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
{
// Retrieve the validation header fields
var webhookRequestOrigin = HttpContext.Request.Headers["WebHook-Request-Origin"].FirstOrDefault();
var webhookRequestCallback = HttpContext.Request.Headers["WebHook-Request-Callback"];
var webhookRequestRate = HttpContext.Request.Headers["WebHook-Request-Rate"];
// Respond with the appropriate origin and allowed rate to
// confirm acceptance of incoming notications
HttpContext.Response.Headers.Add("WebHook-Allowed-Rate", "*");
HttpContext.Response.Headers.Add("WebHook-Allowed-Origin", webhookRequestOrigin);
}
return Ok();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment