diff options
author | Marcel Hellkamp <marc@gsites.de> | 2017-01-06 13:06:41 +0100 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2017-01-06 13:08:13 +0100 |
commit | e90e9e4d9feef8a74006e54e221d1bf8c9dd4799 (patch) | |
tree | 3283458fb63fb99210681d425785c03d305eb3fd | |
parent | 0bf1174acd16c9112a9ef6e37388fe93f8b53524 (diff) | |
download | bottle-e90e9e4d9feef8a74006e54e221d1bf8c9dd4799.tar.gz |
fix #918: AttributeError: 'FileUpload' object has no attribute 'get_header'
-rw-r--r-- | bottle.py | 4 | ||||
-rw-r--r-- | test/test_fileupload.py | 6 |
2 files changed, 9 insertions, 1 deletions
@@ -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) |