Maybe this?

```ruby
port = 
  case scheme
  when 'http'
    @port unless @port == 80
  when 'https'
    @port unless @port == 443
  else
    @port
  end
```

The URL-generated line then has to be:

```ruby
"#{scheme}://#{@host}:#{port}#{object_path_escaped}?temp_url_sig=#{sig}&temp_url_expires=#{expires}"
```

Can @port be nil?