summary refs log tree commit diff
path: root/tests/server.py
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-11-16 15:22:40 +0000
committerGitHub <noreply@github.com>2020-11-16 15:22:40 +0000
commitbebfb9a97b4e6a5cc840dc6906e4aaebd5d7d30d (patch)
tree307ea9eba33d0301b39b79e0e0f9c2913b1418b0 /tests/server.py
parentchangelog (diff)
parentRename `create_test_json_resource` to `create_test_resource` (#8759) (diff)
downloadsynapse-bebfb9a97b4e6a5cc840dc6906e4aaebd5d7d30d.tar.xz
Merge branch 'develop' into rav/pass_site_to_make_request
Diffstat (limited to 'tests/server.py')
-rw-r--r--tests/server.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/server.py b/tests/server.py
index a74fb3fc67..5850eadf3e 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -2,7 +2,7 @@ import json
 import logging
 from collections import deque
 from io import SEEK_END, BytesIO
-from typing import Callable
+from typing import Callable, Iterable, Optional, Tuple, Union
 
 import attr
 from typing_extensions import Deque
@@ -152,6 +152,9 @@ def make_request(
     shorthand=True,
     federation_auth_origin=None,
     content_is_form=False,
+    custom_headers: Optional[
+        Iterable[Tuple[Union[bytes, str], Union[bytes, str]]]
+    ] = None,
 ):
     """
     Make a web request using the given method and path, feed it the
@@ -172,6 +175,8 @@ def make_request(
         content_is_form: Whether the content is URL encoded form data. Adds the
             'Content-Type': 'application/x-www-form-urlencoded' header.
 
+        custom_headers: (name, value) pairs to add as request headers
+
     Returns:
         Tuple[synapse.http.site.SynapseRequest, channel]
     """
@@ -227,6 +232,10 @@ def make_request(
             # Assume the body is JSON
             req.requestHeaders.addRawHeader(b"Content-Type", b"application/json")
 
+    if custom_headers:
+        for k, v in custom_headers:
+            req.requestHeaders.addRawHeader(k, v)
+
     req.requestReceived(method, path, b"1.1")
 
     return req, channel