Repository: sanic-org/sanic-ext (python)

Issue:
[Bug] Dependency injection not working for HEAD requests
**Describe the bug**
Sanic automatically creates `HEAD` endpoints, but dependencies are not injected into these endpoints, causing 500 errors when users HEAD these endpoints.

**Screenshots**
![image](https://user-images.githubusercontent.com/6646473/202834223-30bdbf41-1ae9-4a8e-91a2-091ae194ac56.png)


**To Reproduce**
```python
from sanic import Sanic
from sanic.response import text

app = Sanic('test')

class Foo:
    pass
    
app.ext.add_dependency(Foo, lambda *_: None)

@app.route('/download')
async def handler(req, foo: Foo):
    return text('file')
    
if __name__ == '__main__':
    app.run(port=4321, debug=True)
```

And then `curl -I http://127.0.0.1:4321/download`.

It shows an HTTP 500 response. Sanic reports the following error:

`TypeError: handler() missing 1 required positional argument: 'foo'`

**Expected behavior**

It should receive an HTTP 200 response.

**Environment (please complete the following information):**
 - OS: Windows-10-10.0.19045-SP0
 - Browser: curl 7.83.1
 - Version: Sanic 22.9.0, sanic-ext 22.9.0, sanic-routing 22.8.0

**Additional context**
Many downloaders send a HEAD request before actually downloading. This bug breaks these downloaders.


Pull request:
Injections for HEAD requests
Closes #151 

Patch:
diff --git a/sanic_ext/extensions/http/methods.py b/sanic_ext/extensions/http/methods.py
index 7c9700e..756411d 100644
--- a/sanic_ext/extensions/http/methods.py
+++ b/sanic_ext/extensions/http/methods.py
@@ -84,6 +84,7 @@ def add_auto_handlers(
                                 description="Retrieve HEAD details",
                             )(partial(head_handler, get_handler=route.handler))
                             handler.__auto_handler__ = True
+                            handler.__route_handler__ = route.handler
                             app.add_route(
                                 handler=handler,
                                 uri=group.uri,
diff --git a/sanic_ext/extensions/injection/injector.py b/sanic_ext/extensions/injection/injector.py
index 66c6d16..a375671 100644
--- a/sanic_ext/extensions/injection/injector.py
+++ b/sanic_ext/extensions/injection/injector.py
@@ -79,8 +79,10 @@ def _setup_signature_registry(
                     )
                 ]
             for name, handler in handlers:
-                if hasattr(handler, "__auto_handler__"):
-                    continue
+                if route_handler := getattr(
+                    handler, "__route_handler__", None
+                ):
+                    handler = route_handler
                 if isinstance(handler, partial):
                     if handler.func == app._websocket_handler:
                         handler = handler.args[0]


Test patch:
diff --git a/tests/extensions/injection/test_dependency.py b/tests/extensions/injection/test_dependency.py
index b0b08dd..3f064ab 100644
--- a/tests/extensions/injection/test_dependency.py
+++ b/tests/extensions/injection/test_dependency.py
@@ -29,3 +29,17 @@ def test_dependency_injection(app):
     _, response = app.test_client.get("/getfoo")
 
     assert response.text == "foobar"
+
+
+def test_dependency_injection_head(app):
+    foo = Foo()
+
+    app.ext.dependency(foo)
+
+    @app.get("/getfoo")
+    async def getfoo(request: Request, foo: Foo):
+        return text(foo.bar())
+
+    _, response = app.test_client.head("/getfoo")
+
+    assert int(response.headers.get("content-length", 0)) == 6