zoukankan      html  css  js  c++  java
  • FastAPI *示例

    # ************ CVE Search Proxy ************
    @router.route('/cve-search/{path:path}', methods=['OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
    async def proxy_cve_search_api(req: Request) -> Response:
        """代理CVE Search API接口
    
        具体CVE Search接口文档可访问docker-compose 启动的cve-search实例,通过对应的接口进行访问
        如:接口文档地址: https://127.0.0.1[:expose_port]/api_docs
        """
    
        path = req.path_params.get('path')
        query = str(req.query_params)
        headers = req.headers
        method = req.method
    
        # Get request body
        try:
            body = await req.body()
        except Exception as e:
            return Response(status_code=400, content=f'get request body info error: {e}')
    
        q = '?' + query if query else ''
        cve_search_url = settings.CVE_SEARCH_API_URL + '/' + path + q
        # print(cve_search_url)
    
        # Proxy Request
        async with aiohttp.ClientSession() as session:
            async with session.request(
                    method, cve_search_url, data=body, headers=headers, ssl=settings.CVE_SEARCH_PROXY_SSL_VERIFY
            ) as resp:
                # print('proxy response status:', resp.status, resp.content)
                content = await resp.content.read()
                return Response(content=content, status_code=resp.status, headers=dict(resp.headers))
    
  • 相关阅读:
    [HNOI2010]CITY 城市建设

    [HNOI2011]数学作业
    [NOI2012]美食节
    [HEOI2014]大工程
    [HEOI2013]ALO(待更)
    [HEOI2016/TJOI2016]序列
    贪食蛇(未完待续)
    [HEOI2016/TJOI2016]字符串
    bzoj 2437[Noi2011]兔兔与蛋蛋 黑白染色二分图+博弈+匈牙利新姿势
  • 原文地址:https://www.cnblogs.com/li1234yun/p/15223315.html
Copyright © 2011-2022 走看看