Discard invalid Referer header

If an invalid Referer header is passed, the value is discarded and the Host header fallback is skipped. This also prevents the InvalidURIError when an invalid header is passed (see related #61).