-
-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Allow the ability of sending the headers from the same route #325
Comments
This already existed. Just needed to document! :( |
Just adding the example of headers using jsonify @app.get("/redirect")
async def redirect(request):
return {
"status_code": "307",
"body": "",
"type": "text",
"headers": jsonify({"Location": "redirect_route"}),
} |
Thank you @cirospaciari 😄 |
Helper example: def redirect(location: str, status_code:int = 302):
return {
"status_code": str(status_code),
"body": "",
"type": "text",
"headers": jsonify({"Location": location}),
} Usage: from helpers import redirect
@app.get("/")
def home(request):
... some login logic here ...
if needs_login:
return redirect("/login")
... normal flow here ....
@app.get("/someroute")
def some_route(request):
return redirect("/", 301) # 301 Moved Permanently
|
I don't know why jsonify is needed, I think is just more overhead and also status_code should be int not str, unless you want to send the full status message like "200 OK" this is how socketify.py does: def home(res, req):
res.redirect("/", 301) # 301 Moved Permanently
def home(res, req):
res.write_status("403 Forbidden").end("Forbidden")
def home(res, req):
res.write_status(403).end("Forbidden") Status 200 OK is the default. I think an refactor should allow it to be like: def redirect(location: str, status_code:int = 302):
return {
"status_code": status_code,
"headers": {"Location": location},
} or using tuples instead of dict as an option. |
@cirospaciari , thank you for the examples.
This is a limitation at the moment. This will need to be fixed. And this will also possibly increase a lot of speed issues. |
Current Behavior
Currently, you cannot send the custom headers in the response from you route. Add the ability to do that.
Desired Behavior
Something along these lines, from our discussion on discord with @cirospaciari
Screenshots / Mockups
Alternatives
The text was updated successfully, but these errors were encountered: