Created
May 16, 2009 12:39
-
-
Save cbilson/112666 to your computer and use it in GitHub Desktop.
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
| #light | |
| open System.Web | |
| open System.Collections.Generic | |
| open System.Text.RegularExpressions | |
| let handlers = new List<(string -> bool) * (HttpContext -> unit)>() | |
| let find_handler_for (ctxt:HttpContext) = | |
| handlers |> Seq.tryfind (fun h -> ctxt.Request.Path |> fst h) | |
| let handle (ctxt:HttpContext) : unit = | |
| match find_handler_for ctxt with | |
| | Some(_, h) -> ctxt |> h | |
| | None -> ignore() | |
| let regex_p pattern = fun s -> Regex.IsMatch(s, pattern) | |
| let get pattern handler = | |
| handlers.Add (regex_p pattern, handler) | |
| let post pattern handler = | |
| handlers.Add (regex_p pattern, handler) | |
| type HttpHandler() = | |
| interface IHttpHandler with | |
| member x.ProcessRequest ctxt = handle ctxt | |
| member x.IsReusable with get() = true | |
| do | |
| get "index.html" (fun ctxt -> ignore()) | |
| get "Home/*" (fun ctxt -> ignore()) | |
| post "Customer/New" (fun ctxt -> ignore()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment