dennisv / django-storage-swift

OpenStack Swift storage backend for Django
MIT License
86 stars 60 forks source link

Object PUT requires Content-Length header #74

Closed valerytschopp closed 7 years ago

valerytschopp commented 7 years ago

Some implementation of the Swift object storage require the PUT request to include a valid header 'Content-Length'.

It is typically the case of the Ceph RADOS Gateway.

If the Swift client doesn't sent the Content-Length header in the PUT request, it will fail with the following error:

(sampleenv) tschopp@macvt.switch.ch:~/projects/openstack/django-storage-swift-quickstart/sampleproj$ python manage.py collectstatic --noinput -v3 --clear
Copying '/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/contrib/admin/static/admin/css/base.css'
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
    collected = self.collect()
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
    handler(path, prefixed_path, storage)
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 359, in copy_file
    self.storage.save(prefixed_path, source_file)
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/django/core/files/storage.py", line 54, in save
    return self._save(name, content)
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/swift/storage.py", line 272, in _save
    headers=headers)
  File "/Users/tschopp/projects/openstack/django-storage-swift-quickstart/sampleenv/lib/python2.7/site-packages/swiftclient/client.py", line 1322, in put_object
    raise ClientException.from_response(resp, 'Object PUT failed', body)
swiftclient.exceptions.ClientException: Object PUT failed: https://os.zhdk.cloud.switch.ch/swift/v1/valery-test-django-static/admin/css/base.css 411 Length Required  [first 60 chars of response] <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>\n<title>411 Length Required</title>\n</head><body>\n<h1>Length Required</h1>\n<p>A request of the requested method PUT requires a valid Content-length.<br/>

I have open the pull request #73 to address this issue.

dennisv commented 7 years ago

I've just merged #73