diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2020-11-16 14:45:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 14:45:22 +0000 |
commit | ebc405446e6615d6187a2e29cb33f27dd5bd0841 (patch) | |
tree | 5903e9c8a8776146e604e99ee2d54119c7974999 /tests/server.py | |
parent | Clarify the usecase for an msisdn delegate (#8734) (diff) | |
download | synapse-ebc405446e6615d6187a2e29cb33f27dd5bd0841.tar.xz |
Add a `custom_headers` param to `make_request` (#8760)
Some tests want to set some custom HTTP request headers, so provide a way to do that before calling requestReceived().
Diffstat (limited to 'tests/server.py')
-rw-r--r-- | tests/server.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/server.py b/tests/server.py index 3dd2cfc072..ef03109a6c 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 @@ -139,6 +139,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 @@ -157,6 +160,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] """ @@ -211,6 +216,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 |