Could the values in the header be in a reversed order (http, https)? The code above checks the first value only.