Added header checking to fix bug with basic auth