Repository: cdent/gabbi

Issue:
case-insensitive headers
As far as I can tell, gabbi enforces lowercase headers:

```yaml
response_headers:
    content-type: text/html; charset=utf-8
```

```
... ✓ front page returns HTML
```

vs.

```yaml
response_headers:
    Content-Type: text/html; charset=utf-8
```

```
... E front page returns HTML

ERROR: front page returns HTML
	 "'Content-Type' header not available in response keys: dict_keys(['server', 'content-type', 'access-control-allow-origin', 'date', 'access-control-allow-credentials', 'connection', 'content-location', 'content-length', 'status'])"
```

From my perspective, the second version is more readable - so it would be nice if header name comparisons were case-insensitive.


Discussion:

Patch:
diff --git a/gabbi/handlers.py b/gabbi/handlers.py
index f754d94..d39a987 100644
--- a/gabbi/handlers.py
+++ b/gabbi/handlers.py
@@ -120,6 +120,8 @@ class HeadersResponseHandler(ResponseHandler):
     test_key_value = {}
 
     def action(self, test, header, value):
+        header = header.lower()  # case-insensitive comparison
+
         response = test.response
         header_value = test.replace_template(value)
 


Test patch:
diff --git a/gabbi/tests/test_handlers.py b/gabbi/tests/test_handlers.py
index b18e8ec..b647e80 100644
--- a/gabbi/tests/test_handlers.py
+++ b/gabbi/tests/test_handlers.py
@@ -94,10 +94,16 @@ class HandlersTest(unittest.TestCase):
 
     def test_response_headers(self):
         handler = handlers.HeadersResponseHandler(self.test_class)
+        self.test.response = {'content-type': 'text/plain'}
+
         self.test.test_data = {'response_headers': {
             'content-type': 'text/plain',
         }}
-        self.test.response = {'content-type': 'text/plain'}
+        self._assert_handler(handler)
+
+        self.test.test_data = {'response_headers': {
+            'Content-Type': 'text/plain',
+        }}
         self._assert_handler(handler)
 
     def test_response_headers_regex(self):