summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2017-01-06 13:06:41 +0100
committerMarcel Hellkamp <marc@gsites.de>2017-01-06 13:08:13 +0100
commite90e9e4d9feef8a74006e54e221d1bf8c9dd4799 (patch)
tree3283458fb63fb99210681d425785c03d305eb3fd
parent0bf1174acd16c9112a9ef6e37388fe93f8b53524 (diff)
downloadbottle-e90e9e4d9feef8a74006e54e221d1bf8c9dd4799.tar.gz
fix #918: AttributeError: 'FileUpload' object has no attribute 'get_header'
-rw-r--r--bottle.py4
-rw-r--r--test/test_fileupload.py6
2 files changed, 9 insertions, 1 deletions
diff --git a/bottle.py b/bottle.py
index 1e6e8cf..8015740 100644
--- a/bottle.py
+++ b/bottle.py
@@ -2355,6 +2355,10 @@ class FileUpload(object):
content_type = HeaderProperty('Content-Type')
content_length = HeaderProperty('Content-Length', reader=int, default=-1)
+ def get_header(self, name, default=None):
+ """ Return the value of a header within the mulripart part. """
+ return self.headers.get(name, default)
+
@cached_property
def filename(self):
''' Name of the file on the client file system, but normalized to ensure
diff --git a/test/test_fileupload.py b/test/test_fileupload.py
index 13e8c7a..b8ae56c 100644
--- a/test/test_fileupload.py
+++ b/test/test_fileupload.py
@@ -4,7 +4,7 @@
import unittest
import sys, os.path
import bottle
-from bottle import FileUpload, BytesIO
+from bottle import FileUpload, BytesIO, tob
import tempfile
class TestFileUpload(unittest.TestCase):
@@ -14,6 +14,10 @@ class TestFileUpload(unittest.TestCase):
def test_raw_filename(self):
self.assertEqual(FileUpload(None, None, 'x/x').raw_filename, 'x/x')
+ def test_content_type(self):
+ fu = FileUpload(None, None, None, {"Content-type": "text/plain"})
+ self.assertEqual(fu.content_type, 'text/plain')
+
def assertFilename(self, bad, good):
fu = FileUpload(None, None, bad)
self.assertEqual(fu.filename, good)