有了Bottle,我怎么能偷看http请求的头部而不是接收整个http请求?

时间:2014-12-16 06:45:58

标签: python http file-upload bottle

我不知道瓶子是否可行。 我的网站(由Bottle提供支持)允许用户上传图像文件。但我把它的大小限制在100K。我在Web服务器中使用以下代码来执行此操作。

    uploadLimit = 100 #  100k
    uploadLimitInByte = uploadLimit* 2**10

    print("before call request.headers.get('Content-Length')")
    contentLen =  request.headers.get('Content-Length')

    if contentLen:
        contentLen = int(contentLen)
        if contentLen > uploadLimitInByte:                
            return HTTPResponse('upload limit is 100K')

但是当我点击网页浏览器中的上传按钮上传一个大小为2MB的文件时,似乎服务器正在接收整个2MB的http请求。 我希望上面的代码只接收http标头而不是接收整个http请求。这无法阻止在收到不必要的字节时浪费时间

0 个答案:

没有答案