summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-01-09 17:01:55 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2020-01-09 17:01:55 +0000
commit9f2434d4943cd2cfaa1a16ebac426c41cb2fe136 (patch)
tree4bf4c55e98160ccf7458c869d6486fb82e6cbdd4 /synapse
parentDon't 500 on not providing a Content-Length header to media upload (diff)
downloadsynapse-github/anoa/content_length_header_none.tar.xz
Diffstat (limited to '')
-rw-r--r--synapse/rest/media/v1/upload_resource.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/synapse/rest/media/v1/upload_resource.py b/synapse/rest/media/v1/upload_resource.py
index 2c61df5eb7..b5d3f09c88 100644
--- a/synapse/rest/media/v1/upload_resource.py
+++ b/synapse/rest/media/v1/upload_resource.py
@@ -52,15 +52,14 @@ class UploadResource(DirectServeResource):
         requester = await self.auth.get_user_by_req(request)
         # TODO: The checks here are a bit late. The content will have
         # already been uploaded to a tmp file at this point
-        if not request.hasHeader(b"Content-Length"):
-            raise SynapseError(msg="Request must specify a Content-Length", code=400)
-        content_length = request.getHeader(b"Content-Length").decode("ascii")
-        if int(content_length) > self.max_upload_size:
-            raise SynapseError(
-                msg="Upload request body is too large",
-                code=413,
-                errcode=Codes.TOO_LARGE,
-            )
+        if request.hasHeader(b"Content-Length"):
+            content_length = request.getHeader(b"Content-Length").decode("ascii")
+            if int(content_length) > self.max_upload_size:
+                raise SynapseError(
+                    msg="Upload request body is too large",
+                    code=413,
+                    errcode=Codes.TOO_LARGE,
+                )
 
         upload_name = parse_string(request, b"filename", encoding=None)
         if upload_name: