twisted / twisted/klein

Returning a static file from a route that matches all URLs behaves unexpectedly

Open
#625 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
838
Forks
123
Avg merge
7h 58m
Merged PRs (30d)
12

Description

I am not sure if this is a bug or intended behaviour. But the following code will not return the static file in case the "catchAll" function is called by url that is nested deeper i.e. calling http://localhost:8080/abc works while calling http://localhost:8080/abc/def doesn't work and will return "No Such Resource". The "catchAll" function gets called, but doesn't return the static file. Calling an explicitly declared url path that is nested such as http://localhost:8080/another/test however works.

from twisted.web.static import File

from klein import Klein

app = Klein()

@app.route('/<path:path>') # <- doesn't work if url is nested deeper
def catchAll(request, path):
    print(path)
    return File("./test.html")

@app.route("/test")    # <- works
def test(request):
    return File("./test.html")

@app.route("/another/test") # <- works
def test2(request):
    return File("./test.html")

app.run("localhost", 8080)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Klein example and compare the /abc and /abc/def requests handled by catchAll, then compare them with the explicit /another/test route. Read the @app.route path handling and twisted.web.static.File interaction; done means nested URLs matching path:path return test.html consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.