 
-# TODO: Support custom "404 Not Found" page.
 # TODO: Support custom "500 Internal Error" page.
 
 assertTypes = require "assertTypes"


# The root request handler.
onRequest = (req, res) ->
  req.timestamp = now()

  parts = req.url.split "?"
  req.path = parts[0]
  req.query = parseQuery parts[1]

  req.app = this
  req.res = res
  setProto req, Request

  res.app = this
  res.req = req
  setProto res, Response


    return

  # Prevent long-running requests.
  if app._timeout > 0
    req.setTimeout onTimeout, app._timeout

  # Attempt to handle the request.
  app._layer.try req, res

  # Wait for the response to finish.
  .then ->
