django_handler.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:cloud-functions-python 作者: MartinSahlen 项目源码 文件源码
def handle_http_event(app):
    environ = wsgi(json.loads(sys.stdin.read()))
    app.load_middleware()
    resp = app.get_response(WSGIRequest(environ))

    body = ''
    if resp.streaming:
        for content in resp.streaming_content:
            body += content
    else:
        body = resp.content.decode('utf-8')

    headers = {}
    for header in resp.items():
        headers[header[0]] = header[1]
    resp.close()

    sys.stdout.write(json.dumps({
        'body': body,
        'status_code': resp.status_code,
        'headers': headers,
    }))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号