Repository: falconry/falcon

Issue:
Request.get_header raises the wrong exception
Found an issue that is making exception-handling not very intuitive when dealing with required headers...

```
try:
  my_header = req.get_header('My-Header', required=True)
except falcon.HTTPMissingHeader:
  print 'Missing header'
except falcon.HTTPMissingParam:
  print 'Missing param'
# Prints "Missing param"
```

Basically, calling ``get_header()`` with ``required=True`` should raise a ``HTTPMissingHeader`` exception, when actually what gets raised is ``HTTPMissingParam``.

This also leads to confusing error response messages, since the response title and header refer to a missing, required "query parameter" instead of a "header".

Discussion:

Patch:
diff --git a/falcon/request.py b/falcon/request.py
index b16e154..74915a0 100644
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -599,7 +599,7 @@ class Request(object):
             if not required:
                 return None
 
-            raise HTTPMissingParam(name)
+            raise HTTPMissingHeader(name)
 
     def get_header_as_datetime(self, header, required=False):
         """Return an HTTP header with HTTP-Date values as a datetime.


Test patch:
diff --git a/tests/test_headers.py b/tests/test_headers.py
index f2a689a..654eee9 100644
--- a/tests/test_headers.py
+++ b/tests/test_headers.py
@@ -183,9 +183,14 @@ class TestHeaders(testing.TestBase):
     def test_required_header(self):
         self.simulate_request(self.test_route)
 
-        self.assertRaises(falcon.HTTPBadRequest,
-                          self.resource.req.get_header, 'X-Not-Found',
-                          required=True)
+        try:
+            self.resource.req.get_header('X-Not-Found', required=True)
+            self.fail('falcon.HTTPMissingHeader not raised')
+        except falcon.HTTPMissingHeader as ex:
+            self.assertIsInstance(ex, falcon.HTTPBadRequest)
+            self.assertEqual(ex.title, 'Missing header value')
+            expected_desc = 'The X-Not-Found header is required.'
+            self.assertEqual(ex.description, expected_desc)
 
     def test_no_body_on_100(self):
         self.resource = StatusTestResource(falcon.HTTP_100)
diff --git a/tests/test_query_params.py b/tests/test_query_params.py
index 893afda..d6adbf8 100644
--- a/tests/test_query_params.py
+++ b/tests/test_query_params.py
@@ -94,6 +94,7 @@ class _TestQueryParams(testing.TestBase):
             getattr(req, method_name)('marker', required=True)
             self.fail('falcon.HTTPMissingParam not raised')
         except falcon.HTTPMissingParam as ex:
+            self.assertIsInstance(ex, falcon.HTTPBadRequest)
             self.assertEqual(ex.title, 'Missing query parameter')
             expected_desc = 'The "marker" query parameter is required.'
             self.assertEqual(ex.description, expected_desc)