V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
wangleineo
V2EX  ›  分享创造

用 Python 写了个 web server,求测试

  •  1
     
  •   wangleineo ·
    RealHacker · 2015-09-28 21:52:34 +08:00 · 2755 次点击
    这是一个创建于 3145 天前的主题,其中的信息可能已经有所发展或是发生改变。

    写了一个极简单的 web server ,支持:

    • 静态文件(相当于标准库 SimpleHTTPServer )
    • WSGI 应用 (简单的 WSGI Server )
    • 代理到其他 web 服务
    • 多线程 /多进程处理请求

    代码

    https://github.com/RealHacker/python-gems/tree/master/http_server

    配置文件

    {
        "server":{
            "ip": "127.0.0.1",
            "port": 8000,
            "mode": "thread"
        },
        "routes":{
            "/app": {
                "type": "wsgi",
                "application": "D:/Workspace/Example/wsgi.py"
            },
            "/app/static": {
                "type": "static",
                "dir":  "D:/workspace/static/"
            }, 
            "/app/proxy": {
                "type": "proxy",
                "proxyurl": "http://www.qq.com/"
            }
        }
    }
    

    设置好 config.json 后,即可执行:

    python web_server.py
    

    这个是自己写的原型,所以一定有很多没考虑到的问题,希望有兴趣的可以帮忙跑一下,看看有什么 bug ,或者直接点评代码。良辰在此先行谢过。

    7 条回复    2015-10-09 20:39:41 +08:00
    noli
        1
    noli  
       2015-09-29 12:39:37 +08:00
    这种测试服务器的事情,自己写个脚本压测一下就什么问题都可以发现了啦……
    hiroya
        2
    hiroya  
       2015-09-29 13:15:35 +08:00 via iPad
    …… Windows 目录……看了下代码, Linux 应该兼容吧………_(:3 」∠)_
    wangleineo
        3
    wangleineo  
    OP
       2015-09-29 13:38:20 +08:00
    @noli 不是测性能 是测功能
    @hiroya Linux 可以
    sengxian
        4
    sengxian  
       2015-10-02 17:38:51 +08:00   ❤️ 1
    @wangleineo 安新系统时刚好用了下你的服务器,还不错 http://seng.ink/app-store-os-x-el-captian
    wangleineo
        5
    wangleineo  
    OP
       2015-10-02 20:55:56 +08:00
    @sengxian 多谢支持!
    saber000
        6
    saber000  
       2015-10-09 09:58:23 +08:00
    proxy 模式下对头部处理会有点问题:
    1. 把请求的 cookie 删掉是否不合适?
    2. 返回不光要去掉 content-encoding 和 transfer-encoding,可以参考:
    https://github.com/MrLYC/post_proxy/blob/master/proxy/server.py#L85
    wangleineo
        7
    wangleineo  
    OP
       2015-10-09 20:39:41 +08:00
    @saber000 受教!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3643 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 84ms · UTC 00:42 · PVG 08:42 · LAX 17:42 · JFK 20:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.