You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've encountered a puzzling issue while using blacksheep
Let's take a simple example
fromblacksheepimportApplication, Request, textimportuvicornapp=Application()
child_app=Application()
@child_app.router.get("/")asyncdeftest_header(request: Request):
ifrequest.headers.get_first(b"Authorization") isNone:
returntext("Authentication not in request headers")
else:
returntext("Authentication in request headers")
app.mount_registry.auto_events=Trueapp.mount("/sub-child", child_app)
if__name__=='__main__':
uvicorn.run("main:app", port=8000)
Then we separately access /sub-child and /sub-child/
importrequestsresp=requests.get("http://localhost:8000/sub-child",
headers={"Authorization": "..."})
print(resp.text) # Authentication not in request headersresp=requests.get("http://localhost:8000/sub-child/",
headers={"Authorization": "..."})
print(resp.text) # Authentication in request headers
Judging from the results, /sub-child/ gives the correct output. However, I'm curious as to why accessing /sub-child yields an unexpected result. I assumed that both should essentially function the same way
PS: I recently came across the blacksheep framework on a website which listed Python's ASGI frameworks. It showed that its concurrency was much higher than FastAPI, so after a brief period of learning, I applied it to my project. However, now I'm encountering the issue I mentioned above. While it can be resolved by adding a slash (/) at the end of the URL, I'm still curious about the underlying reason.
In fact, a similar issue arises with cross-origin resource sharing (child_app.use_cors). Accessing /sub-child/ allows successful CORS, but accessing /sub-child results in a failure.
I sincerely ask for your help in answering this. Thank you very much
The text was updated successfully, but these errors were encountered:
Hi @satori1995
Thank You for your kind words. I need to take a look into this, I try looking into this today. As a side note, if your objective is to organize routes into separate Python modules, I don't recommend using mount for that scenario. I recommend using mount only if you wish to integrate applications implemented using other ASGI servers into your app.
I've encountered a puzzling issue while using blacksheep
Let's take a simple example
Then we separately access
/sub-child
and/sub-child/
Judging from the results,
/sub-child/
gives the correct output. However, I'm curious as to why accessing/sub-child
yields an unexpected result. I assumed that both should essentially function the same wayPS: I recently came across the blacksheep framework on a website which listed Python's ASGI frameworks. It showed that its concurrency was much higher than FastAPI, so after a brief period of learning, I applied it to my project. However, now I'm encountering the issue I mentioned above. While it can be resolved by adding a slash (/) at the end of the URL, I'm still curious about the underlying reason.
In fact, a similar issue arises with cross-origin resource sharing (child_app.use_cors). Accessing /sub-child/ allows successful CORS, but accessing /sub-child results in a failure.
I sincerely ask for your help in answering this. Thank you very much
The text was updated successfully, but these errors were encountered: