Add logging support and fix bug with multiple WWW-Authenticate headers