这个路径返回几

👁️ 1 人浏览 💬 0 人评论 ❤️ 添加收藏

按请求模型,/admin 返回的状态码是多少?

贯穿本节的请求模型:status(路径) 交回状态码(/=200、/admin=403、/old=301、其它 404)。visible_on_wire(scheme, 字段):http 明文整段都被看到,https 只有 ip/port 在外面看得见。curl(路径, scheme, cert_ok, insecure):https 且证书没过校验又没加 -k(insecure) 就交回 拒绝,否则交回状态码。

ROUTES = {"/": 200, "/login": 200, "/admin": 403, "/old": 301}


def status(path):
    return ROUTES.get(path, 404)


def visible_on_wire(scheme, field):
    # http 明文:整段都能被中间人看到;https 加密:只有目标 IP/端口在外面看得见
    if scheme == "https":
        return field in ("ip", "port")
    return True


def curl(path, scheme, cert_ok, insecure):
    # 访问:https 且证书没过校验、又没加 -k,就连不上(拒绝);-k 跳过校验照常拿状态码
    if scheme == "https" and not cert_ok and not insecure:
        return "拒绝"
    return status(path)

print(status("/admin"))
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论