Skip to content

Fix automatic TRACE handler for routes with path parameters#291

Open
rhoffman12 wants to merge 1 commit intosanic-org:mainfrom
rhoffman12:trace-fix
Open

Fix automatic TRACE handler for routes with path parameters#291
rhoffman12 wants to merge 1 commit intosanic-org:mainfrom
rhoffman12:trace-fix

Conversation

@rhoffman12
Copy link
Copy Markdown

Automatic TRACE handlers currently throw up errors in all cases where they are applied to routes with path parameters. Example:

# app.py
import sanic
from sanic_ext import Extend, Config

app = sanic.Sanic(__name__)
app.extend(config=Config(http_auto_trace=True))

@app.get('/files/<path:path>')
async def loader(request, path):
    ...
sanic --dev --port 8000 app:app &
curl -X TRACE http://localhost:8000/files/foo

# ⚠️ 500 — Internal Server Error
# ==============================
# add_auto_handlers.<locals>.trace_handler() got an unexpected keyword argument 'path'
# ...

# log:
# ╭ Srv 20:18:18 ERROR:  Exception occurred while handling uri: 'http://example.com/foo/bar/baz?x=y'
# ╰ TypeError: add_auto_handlers.<locals>.trace_handler() got an unexpected keyword argument 'path'

This can be fixed by adding *args, **kwargs to the trace handler function's signature to collect any wayward parameters, similarly to what is already done for the automatic HEAD and OPTIONS handlers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant