Could we get rid of the `tap` and conditional? If no query parameters are passed then we end up with a trailing `?`. How about:

```ruby
uri.path << "?#{uri.query}".chomp('?')
```