geemus/excon — pull request #376 by smashwilson (2014-04-11 17:13:02+00:00)
Title: [wip] Case-insensitive header access

Hello!

I've taken a stab at implementing case-insensitive header access, as discussed in #366 and #363. Because performance is a concern, I've made it lazily trade space for speed: the first time that you access a header that isn't present, `Excon::Headers` will build a case-normalized index and re-attempt the lookup in that. If you never guess wrong about header case, there will be negligible space cost and little slowdown; if you do, there's a one-time penalty of O(n) and all subsequence accesses are still O(1) -- in contrast to `#get_header`, which is always O(n).

I've done some [benchmarking](https://gist.github.com/smashwilson/10416299) to measure how much of a performance hit this will actually be:

```
Loaded 58 headers.
user system total real
hash, with original case: 2.020000 0.000000 2.020000 ( 2.024403)
hash, with permuted case: 43.810000 0.150000 43.960000 ( 47.884542)
Excon::Headers, with original case: 3.520000 0.010000 3.530000 ( 3.587199)
Excon::Headers, with permuted case: 6.390000 0.020000 6.410000 ( 6.651364)
```

This is over 100k accesses in a header hash containing everything I could copy-paste from running `git grep headers` in fog (for somewhat realistic hash collision rates, etc).

/cc @elight @krames