lib/url: Move URL-handling code to lib