Remove query string from uri when empty

When `URI.query` is an empty string `URI.to_s` will leave a trailing
question mark, the true "emptiness" for query string is obtained with
`nil`