Commits

Ian Bicking committed 677443d

Add .head() method (from http://trac.pythonpaste.org/pythonpaste/ticket/371 -- by greut

Comments (0)

Files changed (3)

tests/test_testing.py

     assert res.status_int == 200
     assert res.headers['content-type'] == 'text/plain'
     assert res.content_type == 'text/plain'
+    res = app.head('/')
+    assert res.status_int == 200
+    assert res.headers['content-type'] == 'text/plain'
+    assert res.content_length
+    assert res.body == ''
     raises(Exception, app.get, '/?error=t')
     raises(webtest.AppError, app.get, '/?status=404%20Not%20Found')
     app.get('/?status=404%20Not%20Found', status=404)

webtest/__init__.py

         return self._gen_request('DELETE', url, headers=headers,
                                  extra_environ=extra_environ,status=status,
                                  upload_files=None, expect_errors=expect_errors)
+    
+    def head(self, url, headers=None, extra_environ=None,
+               status=None, expect_errors=False):
+        """
+        Do a HEAD request.  Very like the ``.get()`` method.
+
+        Returns a ``webob.Response`` object.
+        """
+        return self._gen_request('HEAD', url, headers=headers,
+                                 extra_environ=extra_environ,status=status,
+                                 upload_files=None, expect_errors=expect_errors)
 
     def encode_multipart(self, params, files):
         """

webtest/debugapp.py

             header_name = name[len('header-'):]
             headers.append((header_name, value))
     start_response(status, headers)
+    if req.method == 'HEAD':
+        return ['']
     return [body]
 
 def make_debug_app(global_conf):