stolen from wai (yesod?)