Flask + mod_wsgi + HEAD标头处理:无法获取请求的桶旅

时间:2017-11-16 18:58:57

标签: python python-2.7 apache flask mod-wsgi

我有以下堆栈:Flask(python 2.7)+ Apache2 with mod_wsgi。

我有这个简单的路线功能:

@app.route("/upload/<file_name>/", methods=['POST', 'HEAD'])
def upload(file_name):       
    if request.method == 'HEAD':    
        file_size = int(request.headers.get('Content-Length'))
        file_path = os.path.join(storage_path, file_name)

        if not os.path.exists(file_path):
            return general_response(404)    
        else:
            file_size_on_disk = Utils.get_size_of_file(file_path)
            if file_size_on_disk < file_size:
                print "1"
                return general_response(201)
            elif file_size_on_disk == file_size:
                print "2"
                return general_response(200)    
            else:
                print "4"
                return general_response(500)

    # some code

如果我发送HEAD请求没有任何标头 - 我在REST客户端收到了我的请求的正确响应,但是如果我发送带有'Content-Length'标头的HEAD请求有一些值 - 我看到记录:

2

这是正确的行为,因为在这种情况下应执行代码部分,但在打印“2”后服务器无响应 ...

如果我在我的REST客户端中断连接 - 我在日志中看到以下行:

(70008)Partial results are valid but processing is incomplete: mod_wsgi (pid=11509): Unable to get bucket brigade for request

这是我的apache2配置:

<VirtualHost *:443>

    ServerAdmin Admin
    ServerName site.com

    SSLEngine on
    SSLCertificateFile /path/to/cert
    SSLCertificateKeyFile /path/to/key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
         SSLOptions +StdEnvVars
    </FilesMatch>

    <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
                    nokeepalive ssl-unclean-shutdown \
                    downgrade-1.0 force-response-1.0

    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    WSGIScriptAlias / /path/to/app.wsgi

    WSGIDaemonProcess app_name user=worker group=worker processes=1 threads=5

    DocumentRoot /path/to/src/dir
    <Directory /path/to/src/dir>
        LimitRequestBody 4147483647
        WSGIProcessGroup app_name
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>

</VirtualHost>

我真的无法理解为什么接收带有值的标头会破坏wsgi逻辑。

任何帮助/建议将不胜感激!

0 个答案:

没有答案