Skip to content

Instantly share code, notes, and snippets.

@dbarkol
Created January 20, 2020 20:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbarkol/724c3302e3029af1c59183148c8cc1de to your computer and use it in GitHub Desktop.
Save dbarkol/724c3302e3029af1c59183148c8cc1de to your computer and use it in GitHub Desktop.
CloudEvents validation with Azure Functions
public static class TestFuncApi
{
[FunctionName("TestFuncApi")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", "options", Route = null)] HttpRequest req,
ILogger log)
{
if (req.Method == "OPTIONS")
{
// Retrieve the request origin
if (!req.Headers.TryGetValue("WebHook-Request-Origin", out var headerValues))
return new BadRequestObjectResult("Not a valid request");
// Respond with the origin and rate
var webhookRequestOrigin = headerValues.FirstOrDefault();
req.HttpContext.Response.Headers.Add("WebHook-Allowed-Rate", "*");
req.HttpContext.Response.Headers.Add("WebHook-Allowed-Origin", webhookRequestOrigin);
return new OkResult();
}
// Process event notifications
// Do something here....
return new OkObjectResult("OK");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment