Repository: encode/starlette

Issue:
HEAD method + test client
I'm trying to make HEAD requests using the test client. It looks like the full response is being returned.
It seems to work as expected outside of tests (using `uvicorn`).

```python
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from starlette.testclient import TestClient

app = Starlette()


@app.route('/', methods=['GET', 'HEAD'])
def homepage(request):
    return PlainTextResponse('Hello, world!')


def test_homepage_head():
    client = TestClient(app)

    response = client.head('/')

    assert response.status_code == 200
    assert response.text == ''  # This fails, the full response is returned
```

Also, if I don't include `methods=['GET', 'HEAD']` it just returns a 405, checking previous issues, it sounds like HEAD should be included by default if GET is supported ? https://github.com/encode/starlette/issues/45 https://github.com/encode/starlette/issues/12 


Discussion:

Resolving patch:
diff --git a/starlette/routing.py b/starlette/routing.py
--- a/starlette/routing.py
+++ b/starlette/routing.py
@@ -162,7 +162,13 @@ def __init__(
             # Endpoint is a class. Treat it as ASGI.
             self.app = endpoint
 
-        self.methods = methods
+        if methods is None:
+            self.methods = None
+        else:
+            self.methods = set([method.upper() for method in methods])
+            if "GET" in self.methods:
+                self.methods |= set(["HEAD"])
+
         self.path_regex, self.path_format, self.param_convertors = self.compile_path(
             path
         )
diff --git a/starlette/testclient.py b/starlette/testclient.py
--- a/starlette/testclient.py
+++ b/starlette/testclient.py
@@ -173,7 +173,8 @@ async def send(message: Message) -> None:
                 ), 'Received "http.response.body" after response completed.'
                 body = message.get("body", b"")
                 more_body = message.get("more_body", False)
-                raw_kwargs["body"].write(body)
+                if request.method != "HEAD":
+                    raw_kwargs["body"].write(body)
                 if not more_body:
                     raw_kwargs["body"].seek(0)
                     response_complete = True


Test patch:
diff --git a/tests/test_applications.py b/tests/test_applications.py
--- a/tests/test_applications.py
+++ b/tests/test_applications.py
@@ -100,6 +100,10 @@ def test_func_route():
     assert response.status_code == 200
     assert response.text == "Hello, world!"
 
+    response = client.head("/func")
+    assert response.status_code == 200
+    assert response.text == ""
+
 
 def test_async_route():
     response = client.get("/async")
diff --git a/tests/test_responses.py b/tests/test_responses.py
--- a/tests/test_responses.py
+++ b/tests/test_responses.py
@@ -287,3 +287,16 @@ def app(scope):
     assert response.text == "hi"
     assert response.headers["content-length"] == "2"
     assert response.headers["content-type"] == "text/html; charset=utf-8"
+
+
+def test_head_method():
+    def app(scope):
+        async def asgi(receive, send):
+            response = Response("hello, world", media_type="text/plain")
+            await response(receive, send)
+
+        return asgi
+
+    client = TestClient(app)
+    response = client.head("/")
+    assert response.text == ""