Skip to content

chunked response landing page example #346

Answered by RobertoPrevato
TGlock asked this question in Q&A
Discussion options

You must be logged in to vote

Interesting question. I didn't think of documenting this, but I'll add an example to the docs site.

You can achieve that functionality this way, using the get_response_for_file. The example below also includes a Cache-Control response header with max-age=120 seconds.

from blacksheep import Application, Request, Response
from blacksheep.server.files.dynamic import get_response_for_file

app = Application()


@app.router.get("/{page}")
def landing(request: Request, page: str) -> Response:
    # In this case, page can be any file which is a direct child of the CWD
    # TODO: validate the input value because otherwise the user can download anything,
    # for example also application setting…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by RobertoPrevato
Comment options

You must be logged in to vote
2 replies
@TGlock
Comment options

@TGlock
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #345 on May 01, 2023 20:30.