如何在pywebio start_server中定义origin_check

发布于 2025-01-19 13:00:16 字数 541 浏览 5 评论 0原文

我有一个小测试脚本,我想在其中检查 pywebio start_server 参数。但 allowed_originscheck_origin 在我的脚本中似乎都不起作用:

from pywebio import start_server
from pywebio.input import *
from pywebio.output import *

def main():
    put_markdown("## just a small start_server test")

def my_origin_check(value):
    print(value)
    return False

if __name__ == '__main__':
    start_server(main, check_origin=my_origin_check, debug=True, port=5000)

我看不出 my_origin_check 没有被调用的原因 - 我'我眼睛瞎了……有什么帮助吗?

I have a small test script where I'd like to check the pywebio start_server arguments. But neither allowed_origins nor check_origin seems to work in my script:

from pywebio import start_server
from pywebio.input import *
from pywebio.output import *

def main():
    put_markdown("## just a small start_server test")

def my_origin_check(value):
    print(value)
    return False

if __name__ == '__main__':
    start_server(main, check_origin=my_origin_check, debug=True, port=5000)

I can't see the reason why my_origin_check doesn't get called - I'm blind on my eyes ... any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2025-01-26 13:00:16

根据源代码start_server()

check_origin_func = lambda origin, handler: _is_same_site(origin, handler) or check_origin(origin)

仅当应用程序 url 和底层 websocket api 不在同一主机上时,才会调用用户定义的 check_origin 函数

According to the source code of start_server():

check_origin_func = lambda origin, handler: _is_same_site(origin, handler) or check_origin(origin)

the user-defined check_origin function only is called when the application url and the underlying websocket api is not on same host

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文