summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--changelog.d/4498.misc1
-rw-r--r--changelog.d/4511.feature1
-rw-r--r--synapse/config/server.py2
-rw-r--r--synapse/http/federation/matrix_federation_agent.py33
-rw-r--r--tests/http/federation/test_matrix_federation_agent.py1
5 files changed, 16 insertions, 22 deletions
diff --git a/changelog.d/4498.misc b/changelog.d/4498.misc
new file mode 100644
index 0000000000..8b3bc94a34
--- /dev/null
+++ b/changelog.d/4498.misc
@@ -0,0 +1 @@
+Clarify documentation for the `public_baseurl` config param
diff --git a/changelog.d/4511.feature b/changelog.d/4511.feature
new file mode 100644
index 0000000000..bda713adf9
--- /dev/null
+++ b/changelog.d/4511.feature
@@ -0,0 +1 @@
+Implement MSC1708 (.well-known routing for server-server federation)
\ No newline at end of file
diff --git a/synapse/config/server.py b/synapse/config/server.py
index 22dcc87d8a..268a43ff00 100644
--- a/synapse/config/server.py
+++ b/synapse/config/server.py
@@ -261,7 +261,7 @@ class ServerConfig(Config):
         # enter into the 'custom HS URL' field on their client. If you
         # use synapse with a reverse proxy, this should be the URL to reach
         # synapse via the proxy.
-        # public_baseurl: https://example.com:8448/
+        # public_baseurl: https://example.com/
 
         # Set the soft limit on the number of file descriptors synapse can use
         # Zero is used to indicate synapse should set the soft limit to the
diff --git a/synapse/http/federation/matrix_federation_agent.py b/synapse/http/federation/matrix_federation_agent.py
index 07c72c9351..f81fcd4301 100644
--- a/synapse/http/federation/matrix_federation_agent.py
+++ b/synapse/http/federation/matrix_federation_agent.py
@@ -12,7 +12,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-import cgi
 import json
 import logging
 
@@ -263,37 +262,31 @@ class MatrixFederationAgent(object):
         # FIXME: add a cache
 
         uri = b"https://%s/.well-known/matrix/server" % (server_name, )
-        logger.info("Fetching %s", uri.decode("ascii"))
+        uri_str = uri.decode("ascii")
+        logger.info("Fetching %s", uri_str)
         try:
             response = yield make_deferred_yieldable(
                 self._well_known_agent.request(b"GET", uri),
             )
         except Exception as e:
-            logger.info(
-                "Connection error fetching %s: %s",
-                uri.decode("ascii"), e,
-            )
+            logger.info("Connection error fetching %s: %s", uri_str, e)
             defer.returnValue(None)
 
         body = yield make_deferred_yieldable(readBody(response))
 
         if response.code != 200:
-            logger.info(
-                "Error response %i from %s: %s",
-                response.code, uri.decode("ascii"), body,
-            )
+            logger.info("Error response %i from %s", response.code, uri_str)
             defer.returnValue(None)
 
-        content_types = response.headers.getRawHeaders(u'content-type')
-        if content_types is None:
-            raise Exception("no content-type header on .well-known response")
-        content_type, _opts = cgi.parse_header(content_types[-1])
-        if content_type != 'application/json':
-            raise Exception("content-type not application/json on .well-known response")
-        parsed_body = json.loads(body.decode('utf-8'))
-        logger.info("Response from .well-known: %s", parsed_body)
-        if not isinstance(parsed_body, dict) or "m.server" not in parsed_body:
-            raise Exception("invalid .well-known response")
+        try:
+            parsed_body = json.loads(body.decode('utf-8'))
+            logger.info("Response from .well-known: %s", parsed_body)
+            if not isinstance(parsed_body, dict):
+                raise Exception("not a dict")
+            if "m.server" not in parsed_body:
+                raise Exception("Missing key 'm.server'")
+        except Exception as e:
+            raise Exception("invalid .well-known response from %s: %s" % (uri_str, e,))
         defer.returnValue(parsed_body["m.server"].encode("ascii"))
 
 
diff --git a/tests/http/federation/test_matrix_federation_agent.py b/tests/http/federation/test_matrix_federation_agent.py
index bd80dd0cb6..11ea8ef10c 100644
--- a/tests/http/federation/test_matrix_federation_agent.py
+++ b/tests/http/federation/test_matrix_federation_agent.py
@@ -146,7 +146,6 @@ class MatrixFederationAgentTests(TestCase):
             [b'testserv'],
         )
         # send back a response
-        request.responseHeaders.setRawHeaders(b'Content-Type', [b'application/json'])
         request.write(b'{ "m.server": "%s" }' % (target_server,))
         request.finish()