Skip to content

Instantly share code, notes, and snippets.

@cbilson
Created May 16, 2009 12:39
Show Gist options
  • Save cbilson/112666 to your computer and use it in GitHub Desktop.
Save cbilson/112666 to your computer and use it in GitHub Desktop.
#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