浏览代码

HUE-2893 [desktop] Backport CherryPy SSL file upload fix

This backports a CherryPy patch that fixes an issue with uploading
files with HTTPS, where CherryPy was expecting that the amount of
bytes uploaded matched the Content-Size header, which is not the
case with HTTPS.

https://bitbucket.org/cherrypy/cherrypy/pull-requests/14
Erick Tryzelaar 10 年之前
父节点
当前提交
234841a
共有 2 个文件被更改,包括 14 次插入3 次删除
  1. 5 2
      apps/filebrowser/src/filebrowser/views_test.py
  2. 9 1
      desktop/core/src/desktop/lib/wsgiserver.py

+ 5 - 2
apps/filebrowser/src/filebrowser/views_test.py

@@ -34,6 +34,7 @@ from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.test_utils import grant_access, add_to_group
 from hadoop import pseudo_hdfs4
+from hadoop.conf import UPLOAD_CHUNK_SIZE
 from filebrowser.views import location_to_url
 
 from conf import MAX_SNAPPY_DECOMPRESSION_SIZE
@@ -797,7 +798,9 @@ class TestFileBrowserWithHadoop(object):
 
   def test_upload_file(self):
     with tempfile.NamedTemporaryFile() as local_file:
-      local_file.write('01234' * 1024 * 1024)
+      # Make sure we can upload larger than the UPLOAD chunk size
+      file_size = UPLOAD_CHUNK_SIZE.get() * 2
+      local_file.write('0' * file_size)
       local_file.flush()
 
       prefix = self.cluster.fs_prefix + '/test_upload_file'
@@ -827,7 +830,7 @@ class TestFileBrowserWithHadoop(object):
       assert_equal(stats['group'], USER_NAME)
 
       f = self.cluster.fs.open(HDFS_FILE)
-      actual = f.read(1024 * 1024 * 5)
+      actual = f.read(file_size)
       expected = file(LOCAL_FILE).read()
       assert_equal(actual, expected, 'files do not match: %s != %s' % (len(actual), len(expected)))
 

+ 9 - 1
desktop/core/src/desktop/lib/wsgiserver.py

@@ -827,7 +827,15 @@ if not _fileobject_uses_str_type:
                         buf.write(data)
                         del data  # explicit free
                         break
-                    assert n <= left, "recv(%d) returned %d bytes" % (left, n)
+                    # NOTE: (HUE-2893) This was backported from CherryPy PR
+                    # #14, which fixes uploading chunked files with SSL.
+                    elif n > left:
+                        # Could happen with SSL transport. Differ
+                        # extra data read to the next call
+                        buf.write(data[:left])
+                        self._rbuf.write(data[left:])
+                        del data
+                        break
                     buf.write(data)
                     buf_len += n
                     del data  # explicit free