Last active
July 28, 2017 15:05
-
-
Save scottoffen/b26a928c8c962188230307ac1c1b3df0 to your computer and use it in GitHub Desktop.
Grapevine: Input validation
This file contains hidden or 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
// the context will be passed into the method automatically by the router | |
server.Router.BeforeRouting += context => | |
{ | |
// Do your input validation here | |
if (!context.Request.Payload.Contains("elephant")) | |
{ | |
// by sending a response to the request, no additional processing will occur. | |
context.Response.SendResponse(HttpStatusCode.BadRequest, "no elephants allowed"); | |
} | |
/* | |
* No need to do anything else. | |
* Once all before handlers have executed, the | |
* routes will be executed, unless one of the event | |
* handlers have already sent a response. | |
*/ | |
}; | |
server.Router.BeforeRouting += context => | |
{ | |
/* | |
* You can have multiples of these, too, if you | |
* are initializing multiple autonomous things. | |
*/ | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment