Repository: encode/uvicorn

Issue:
HEAD request raise error with h11
I'm using the same example from the Readme but running with h11:

```bash
uvicorn --http h11 app:App
```

When I make a HEAD request, I get this error:

```bash
> uvicorn --http h11 app:App
INFO: Started server process [509]
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: ('127.0.0.1', 43588) - "HEAD / HTTP/1.1" 200
ERROR: Exception in ASGI application
Traceback (most recent call last):
  File "/home/merlin/workspace/uvicorn_test_2/.venv/lib/python3.6/site-packages/uvicorn/protocols/http/h11_impl.py", line 394, in run_asgi
    result = await asgi(self.receive, self.send)
  File "./app.py", line 19, in __call__
    'body': b'Hello, world!',
  File "/home/merlin/workspace/uvicorn_test_2/.venv/lib/python3.6/site-packages/uvicorn/protocols/http/h11_impl.py", line 486, in send
    event = h11.Data()
  File "/home/merlin/workspace/uvicorn_test_2/.venv/lib/python3.6/site-packages/h11/_events.py", line 39, in __init__
    .format(field, self.__class__.__name__))
TypeError: missing required kwarg data for Data
^CINFO: Stopping server process [509]
```
```


Discussion:

Resolving patch:
diff --git a/uvicorn/protocols/http/h11_impl.py b/uvicorn/protocols/http/h11_impl.py
--- a/uvicorn/protocols/http/h11_impl.py
+++ b/uvicorn/protocols/http/h11_impl.py
@@ -483,7 +483,7 @@ async def send(self, message):
 
             # Write response body
             if self.scope["method"] == "HEAD":
-                event = h11.Data()
+                event = h11.Data(data=b'')
             else:
                 event = h11.Data(data=body)
             output = self.conn.send(event)


Test patch:
diff --git a/tests/protocols/test_http.py b/tests/protocols/test_http.py
--- a/tests/protocols/test_http.py
+++ b/tests/protocols/test_http.py
@@ -242,33 +242,33 @@ def app(scope):
 
 @pytest.mark.parametrize("protocol_cls", [HttpToolsProtocol, H11Protocol])
 def test_chunked_encoding_empty_body(protocol_cls):
-    class App():
-        def __init__(self, scope):
-            assert scope['type'] == 'http'
-            self.scope = scope
-
-        async def __call__(self, receive, send):
-            await send({
-                'type': 'http.response.start',
-                'status': 200,
-                'headers': [
-                    [b'content-type', b'text/plain'],
-                ],
-            })
-            await send({
-                'type': 'http.response.body',
-                'body': b'',
-            })
+    def app(scope):
+        return Response(
+            b"Hello, world!", status_code=200, headers={"transfer-encoding": "chunked"}
+        )
 
-    protocol = get_connected_protocol(App, protocol_cls)
+    protocol = get_connected_protocol(app, protocol_cls)
     protocol.data_received(SIMPLE_GET_REQUEST)
     protocol.loop.run_one()
     assert b"HTTP/1.1 200 OK" in protocol.transport.buffer
-    print(protocol.transport.buffer)
     assert protocol.transport.buffer.count(b'0\r\n\r\n') == 1
     assert not protocol.transport.is_closing()
 
 
+@pytest.mark.parametrize("protocol_cls", [HttpToolsProtocol, H11Protocol])
+def test_chunked_encoding_head_request(protocol_cls):
+    def app(scope):
+        return Response(
+            b"Hello, world!", status_code=200, headers={"transfer-encoding": "chunked"}
+        )
+
+    protocol = get_connected_protocol(app, protocol_cls)
+    protocol.data_received(SIMPLE_HEAD_REQUEST)
+    protocol.loop.run_one()
+    assert b"HTTP/1.1 200 OK" in protocol.transport.buffer
+    assert not protocol.transport.is_closing()
+
+
 @pytest.mark.parametrize("protocol_cls", [HttpToolsProtocol, H11Protocol])
 def test_pipelined_requests(protocol_cls):
     def app(scope):