fix ValueError: invalid content length with swift over UWSGI

We're using Swift over UWSGI, with the correct UWSGI parameters. That is:

plugins = python3,transformation_chunked
http-auto-chunked = true
http-chunked-input = true
http-raw-body = true
route = .* addheader:Date: ${httptime[]}
route-run = chunked:
wsgi-manage-chunked-input = true

In this mode, the Content-Length: header may not be present, and
instead, swift provides a Transfer-Encoding: chunked. This isn't what
Horizon expects, and this leads to Django crashing with a Content-Length
set to None.

This very simple patch skips populating Content-Length if the swift
object has its obj.bytes set to None.

Change-Id: I602709b8eaf2368dbdb1a9ce6ed84b031c5b0b4d
This commit is contained in:
Thomas Goirand 2022-01-31 15:34:05 +01:00
parent 047b81e979
commit e34e0ea73f
1 changed files with 2 additions and 1 deletions

View File

@ -252,7 +252,8 @@ class Object(generic.View):
safe = filename.replace(",", "")
response['Content-Disposition'] = 'attachment; filename="%s"' % safe
response['Content-Type'] = 'application/octet-stream'
response['Content-Length'] = obj.bytes
if obj.bytes is not None:
response['Content-Length'] = obj.bytes
return response