This matches the text of the spec a little more closely in many cases and is also more efficient than serializing the URL path. (cherry picked from commit ffe070d7f9164ff51644f8d912b580a0b291e26a)