Merge "symlink: Allow symlinks to be created via chunk-encoded PUTs"
This commit is contained in:
@@ -425,7 +425,11 @@ class SymlinkObjectContext(WSGIContext):
|
|||||||
:param req: HTTP PUT object request
|
:param req: HTTP PUT object request
|
||||||
:returns: Response Iterator
|
:returns: Response Iterator
|
||||||
"""
|
"""
|
||||||
if req.content_length != 0:
|
if req.content_length is None:
|
||||||
|
has_body = (req.body_file.read(1) != b'')
|
||||||
|
else:
|
||||||
|
has_body = (req.content_length != 0)
|
||||||
|
if has_body:
|
||||||
raise HTTPBadRequest(
|
raise HTTPBadRequest(
|
||||||
body='Symlink requests require a zero byte body',
|
body='Symlink requests require a zero byte body',
|
||||||
request=req,
|
request=req,
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import io
|
||||||
import json
|
import json
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
@@ -91,6 +92,21 @@ class TestSymlinkMiddleware(TestSymlinkMiddlewareBase):
|
|||||||
val = hdrs.get('X-Object-Sysmeta-Container-Update-Override-Etag')
|
val = hdrs.get('X-Object-Sysmeta-Container-Update-Override-Etag')
|
||||||
self.assertEqual(val, '%s; symlink_target=c1/o' % MD5_OF_EMPTY_STRING)
|
self.assertEqual(val, '%s; symlink_target=c1/o' % MD5_OF_EMPTY_STRING)
|
||||||
|
|
||||||
|
def test_symlink_chunked_put(self):
|
||||||
|
self.app.register('PUT', '/v1/a/c/symlink', swob.HTTPCreated, {})
|
||||||
|
req = Request.blank('/v1/a/c/symlink', method='PUT',
|
||||||
|
headers={'X-Symlink-Target': 'c1/o'},
|
||||||
|
environ={'wsgi.input': io.BytesIO(b'')})
|
||||||
|
self.assertIsNone(req.content_length) # sanity
|
||||||
|
status, headers, body = self.call_sym(req)
|
||||||
|
self.assertEqual(status, '201 Created')
|
||||||
|
method, path, hdrs = self.app.calls_with_headers[0]
|
||||||
|
val = hdrs.get('X-Object-Sysmeta-Symlink-Target')
|
||||||
|
self.assertEqual(val, 'c1/o')
|
||||||
|
self.assertNotIn('X-Object-Sysmeta-Symlink-Target-Account', hdrs)
|
||||||
|
val = hdrs.get('X-Object-Sysmeta-Container-Update-Override-Etag')
|
||||||
|
self.assertEqual(val, '%s; symlink_target=c1/o' % MD5_OF_EMPTY_STRING)
|
||||||
|
|
||||||
def test_symlink_put_different_account(self):
|
def test_symlink_put_different_account(self):
|
||||||
self.app.register('PUT', '/v1/a/c/symlink', swob.HTTPCreated, {})
|
self.app.register('PUT', '/v1/a/c/symlink', swob.HTTPCreated, {})
|
||||||
req = Request.blank('/v1/a/c/symlink', method='PUT',
|
req = Request.blank('/v1/a/c/symlink', method='PUT',
|
||||||
|
Reference in New Issue
Block a user