Fix authentication middleware when port part of url
Support IO object being passed to #hex_digest