@perek actually I was asking myself the same question while looking at this code today! It was introduced to properly handle insensitive headers merging in https://github.com/angular/angular.js/commit/53359d549e364759d5b382c229f7d326799bf418

Then again, with indexing we would be trading memory for speed as we would need to keep an indexing array in memory.  In any case I don't think it has much practical implications as numbers of headers to consider is usually < 5 so no need to split hairs over it. But yeh, it could have been written  differently.

My suggestion: let's fix the underlying issue in this PR and think of optimisations in a separate PR. 

Could you remove duplicated tests and squash commits?