summary refs log tree commit diff
path: root/synapse/http/server.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-10-16 17:21:03 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2020-10-16 17:21:03 +0100
commit3442b28a1bb92d86e9694bf3af8d34f7b2ecbfc3 (patch)
tree0dab83defbedef93ea554778ec4d907b8abc4b75 /synapse/http/server.py
parentMerge commit '2a89ce8cd' into anoa/dinsic_release_1_21_x (diff)
parentImplement handling of HTTP HEAD requests. (#7999) (diff)
downloadsynapse-3442b28a1bb92d86e9694bf3af8d34f7b2ecbfc3.tar.xz
Merge commit '681250980' into anoa/dinsic_release_1_21_x
* commit '681250980':
  Implement handling of HTTP HEAD requests. (#7999)
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r--synapse/http/server.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py

index d4f9ad6e67..94ab29974a 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py
@@ -242,10 +242,12 @@ class _AsyncResource(resource.Resource, metaclass=abc.ABCMeta): no appropriate method exists. Can be overriden in sub classes for different routing. """ + # Treat HEAD requests as GET requests. + request_method = request.method.decode("ascii") + if request_method == "HEAD": + request_method = "GET" - method_handler = getattr( - self, "_async_render_%s" % (request.method.decode("ascii"),), None - ) + method_handler = getattr(self, "_async_render_%s" % (request_method,), None) if method_handler: raw_callback_return = method_handler(request) @@ -362,11 +364,15 @@ class JsonResource(DirectServeJsonResource): A tuple of the callback to use, the name of the servlet, and the key word arguments to pass to the callback """ + # Treat HEAD requests as GET requests. request_path = request.path.decode("ascii") + request_method = request.method + if request_method == b"HEAD": + request_method = b"GET" # Loop through all the registered callbacks to check if the method # and path regex match - for path_entry in self.path_regexs.get(request.method, []): + for path_entry in self.path_regexs.get(request_method, []): m = path_entry.pattern.match(request_path) if m: # We found a match! @@ -579,7 +585,7 @@ def set_cors_headers(request: Request): """ request.setHeader(b"Access-Control-Allow-Origin", b"*") request.setHeader( - b"Access-Control-Allow-Methods", b"GET, POST, PUT, DELETE, OPTIONS" + b"Access-Control-Allow-Methods", b"GET, HEAD, POST, PUT, DELETE, OPTIONS" ) request.setHeader( b"Access-Control-Allow-Headers",