CloudEvents validation with Azure Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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