Extract uri encoding sanitize methods

- Extract encoded uri sanitization logic as a step towards being able to run it outside of rack.
- Fix URI.escape deprecation warning
- Use Encoding constants