Skip to content

Instantly share code, notes, and snippets.

@mattgu74
Created July 4, 2011 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattgu74/1063346 to your computer and use it in GitHub Desktop.
Save mattgu74/1063346 to your computer and use it in GitHub Desktop.
Try to parse domain and subdomain before the url
urlsinit(req : http_request) : Parser.general_parser(resource) =
parser
| {Rule.debug_parse_string(s -> Log.notice("URL",s))} Rule.fail -> error("")
| "/test" -> Resource.page("test", <>The domain is : {HttpRequest.Generic.get_host(req)?"none"}<br/>The url is "/test"</>)
| url=(.*) -> render_page(Text.to_string(url))
urls : Parser.general_parser(http_request -> resource) =
parser
| {Rule.debug_parse_string(s -> Log.notice("URL",s))} Rule.fail -> error("")
| .* -> req ->
myparser =
parser
| {Rule.debug_parse_string(s -> Log.notice("DOMAIN",s))} Rule.fail -> error("")
| .* -> Parser.parse(urlsinit(req), HttpRequest.Generic.get_uri(req))
Parser.parse(myparser, HttpRequest.Generic.get_host(req)?"")
server = Server.make(urls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment