summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/http')
-rw-r--r--synapse/http/matrixfederationclient.py14
-rw-r--r--synapse/http/servlet.py56
2 files changed, 31 insertions, 39 deletions
diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py

index 1998990a14..b8849c0150 100644 --- a/synapse/http/matrixfederationclient.py +++ b/synapse/http/matrixfederationclient.py
@@ -65,13 +65,9 @@ from synapse.http.client import ( read_body_with_max_size, ) from synapse.http.federation.matrix_federation_agent import MatrixFederationAgent +from synapse.logging import opentracing from synapse.logging.context import make_deferred_yieldable -from synapse.logging.opentracing import ( - inject_active_span_byte_dict, - set_tag, - start_active_span, - tags, -) +from synapse.logging.opentracing import set_tag, start_active_span, tags from synapse.types import ISynapseReactor, JsonDict from synapse.util import json_decoder from synapse.util.async_helpers import timeout_deferred @@ -322,7 +318,9 @@ class MatrixFederationHttpClient: # We need to use a DNS resolver which filters out blacklisted IP # addresses, to prevent DNS rebinding. self.reactor = BlacklistingReactorWrapper( - hs.get_reactor(), None, hs.config.federation_ip_range_blacklist + hs.get_reactor(), + hs.config.federation_ip_range_whitelist, + hs.config.federation_ip_range_blacklist, ) # type: ISynapseReactor user_agent = hs.version_string @@ -497,7 +495,7 @@ class MatrixFederationHttpClient: # Inject the span into the headers headers_dict = {} # type: Dict[bytes, List[bytes]] - inject_active_span_byte_dict(headers_dict, request.destination) + opentracing.inject_header_dict(headers_dict, request.destination) headers_dict[b"User-Agent"] = [self.version_string_bytes] diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py
index 89991e7127..07eb4f439b 100644 --- a/synapse/http/servlet.py +++ b/synapse/http/servlet.py
@@ -200,36 +200,6 @@ def parse_string( args, name, default, required, allowed_values, encoding ) -def parse_list_from_args( - args: Dict[bytes, List[bytes]], - name: Union[bytes, str], - encoding: Optional[str] = "ascii", -): - """Parse and optionally decode a list of values from request query parameters. - - Args: - args: A dictionary of query parameters from a request. - name: The name of the query parameter to extract values from. If given as bytes, - will be decoded as "ascii". - encoding: An optional encoding that is used to decode each parameter value with. - - Raises: - KeyError: If the given `name` does not exist in `args`. - SynapseError: If an argument was not encoded with the specified `encoding`. - """ - if not isinstance(name, bytes): - name = name.encode("ascii") - args_list = args[name] - - if encoding: - # Decode each argument value - try: - args_list = [value.decode(encoding) for value in args_list] - except ValueError: - raise SynapseError(400, "Query parameter %r must be %s" % (name, encoding)) - - return args_list - def _parse_string_value( value: bytes, @@ -324,6 +294,30 @@ def parse_strings_from_args( return default +@overload +def parse_string_from_args( + args: Dict[bytes, List[bytes]], + name: str, + default: Optional[str] = None, + required: Literal[True] = True, + allowed_values: Optional[Iterable[str]] = None, + encoding: str = "ascii", +) -> str: + ... + + +@overload +def parse_string_from_args( + args: Dict[bytes, List[bytes]], + name: str, + default: Optional[str] = None, + required: bool = False, + allowed_values: Optional[Iterable[str]] = None, + encoding: str = "ascii", +) -> Optional[str]: + ... + + def parse_string_from_args( args: Dict[bytes, List[bytes]], name: str, @@ -460,7 +454,7 @@ class RestServlet: """ def register(self, http_server): - """ Register this servlet with the given HTTP server. """ + """Register this servlet with the given HTTP server.""" patterns = getattr(self, "PATTERNS", None) if patterns: for method in ("GET", "PUT", "POST", "DELETE"):