mirror of
https://github.com/element-hq/synapse
synced 2024-08-19 19:40:20 +00:00
Merge pull request #413 from matrix-org/markjh/reuse_http_client
Reuse a single http client, rather than creating new ones
This commit is contained in:
commit
5dc09e82c4
3 changed files with 10 additions and 18 deletions
|
@ -20,7 +20,6 @@ from synapse.api.errors import (
|
|||
CodeMessageException
|
||||
)
|
||||
from ._base import BaseHandler
|
||||
from synapse.http.client import SimpleHttpClient
|
||||
from synapse.util.async import run_on_reactor
|
||||
from synapse.api.errors import SynapseError
|
||||
|
||||
|
@ -35,13 +34,12 @@ class IdentityHandler(BaseHandler):
|
|||
def __init__(self, hs):
|
||||
super(IdentityHandler, self).__init__(hs)
|
||||
|
||||
self.http_client = hs.get_simple_http_client()
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def threepid_from_creds(self, creds):
|
||||
yield run_on_reactor()
|
||||
|
||||
# TODO: get this from the homeserver rather than creating a new one for
|
||||
# each request
|
||||
http_client = SimpleHttpClient(self.hs)
|
||||
# XXX: make this configurable!
|
||||
# trustedIdServers = ['matrix.org', 'localhost:8090']
|
||||
trustedIdServers = ['matrix.org', 'vector.im']
|
||||
|
@ -67,7 +65,7 @@ class IdentityHandler(BaseHandler):
|
|||
|
||||
data = {}
|
||||
try:
|
||||
data = yield http_client.get_json(
|
||||
data = yield self.http_client.get_json(
|
||||
"https://%s%s" % (
|
||||
id_server,
|
||||
"/_matrix/identity/api/v1/3pid/getValidated3pid"
|
||||
|
@ -85,7 +83,6 @@ class IdentityHandler(BaseHandler):
|
|||
def bind_threepid(self, creds, mxid):
|
||||
yield run_on_reactor()
|
||||
logger.debug("binding threepid %r to %s", creds, mxid)
|
||||
http_client = SimpleHttpClient(self.hs)
|
||||
data = None
|
||||
|
||||
if 'id_server' in creds:
|
||||
|
@ -103,7 +100,7 @@ class IdentityHandler(BaseHandler):
|
|||
raise SynapseError(400, "No client_secret in creds")
|
||||
|
||||
try:
|
||||
data = yield http_client.post_urlencoded_get_json(
|
||||
data = yield self.http_client.post_urlencoded_get_json(
|
||||
"https://%s%s" % (
|
||||
id_server, "/_matrix/identity/api/v1/3pid/bind"
|
||||
),
|
||||
|
@ -121,7 +118,6 @@ class IdentityHandler(BaseHandler):
|
|||
@defer.inlineCallbacks
|
||||
def requestEmailToken(self, id_server, email, client_secret, send_attempt, **kwargs):
|
||||
yield run_on_reactor()
|
||||
http_client = SimpleHttpClient(self.hs)
|
||||
|
||||
params = {
|
||||
'email': email,
|
||||
|
@ -131,7 +127,7 @@ class IdentityHandler(BaseHandler):
|
|||
params.update(kwargs)
|
||||
|
||||
try:
|
||||
data = yield http_client.post_urlencoded_get_json(
|
||||
data = yield self.http_client.post_urlencoded_get_json(
|
||||
"https://%s%s" % (
|
||||
id_server,
|
||||
"/_matrix/identity/api/v1/validate/email/requestToken"
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# limitations under the License.
|
||||
|
||||
from synapse.push import Pusher, PusherConfigException
|
||||
from synapse.http.client import SimpleHttpClient
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
|
@ -46,7 +45,7 @@ class HttpPusher(Pusher):
|
|||
"'url' required in data for HTTP pusher"
|
||||
)
|
||||
self.url = data['url']
|
||||
self.httpCli = SimpleHttpClient(self.hs)
|
||||
self.http_client = _hs.get_simple_http_client()
|
||||
self.data_minus_url = {}
|
||||
self.data_minus_url.update(self.data)
|
||||
del self.data_minus_url['url']
|
||||
|
@ -107,7 +106,7 @@ class HttpPusher(Pusher):
|
|||
if not notification_dict:
|
||||
defer.returnValue([])
|
||||
try:
|
||||
resp = yield self.httpCli.post_json_get_json(self.url, notification_dict)
|
||||
resp = yield self.http_client.post_json_get_json(self.url, notification_dict)
|
||||
except:
|
||||
logger.warn("Failed to push %s ", self.url)
|
||||
defer.returnValue(False)
|
||||
|
@ -138,7 +137,7 @@ class HttpPusher(Pusher):
|
|||
}
|
||||
}
|
||||
try:
|
||||
resp = yield self.httpCli.post_json_get_json(self.url, d)
|
||||
resp = yield self.http_client.post_json_get_json(self.url, d)
|
||||
except:
|
||||
logger.exception("Failed to push %s ", self.url)
|
||||
defer.returnValue(False)
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.errors import SynapseError, LoginError, Codes
|
||||
from synapse.http.client import SimpleHttpClient
|
||||
from synapse.types import UserID
|
||||
from base import ClientV1RestServlet, client_path_patterns
|
||||
|
||||
|
@ -51,6 +50,7 @@ class LoginRestServlet(ClientV1RestServlet):
|
|||
self.cas_server_url = hs.config.cas_server_url
|
||||
self.cas_required_attributes = hs.config.cas_required_attributes
|
||||
self.servername = hs.config.server_name
|
||||
self.http_client = hs.get_simple_http_client()
|
||||
|
||||
def on_GET(self, request):
|
||||
flows = []
|
||||
|
@ -98,15 +98,12 @@ class LoginRestServlet(ClientV1RestServlet):
|
|||
# TODO Delete this after all CAS clients switch to token login instead
|
||||
elif self.cas_enabled and (login_submission["type"] ==
|
||||
LoginRestServlet.CAS_TYPE):
|
||||
# TODO: get this from the homeserver rather than creating a new one for
|
||||
# each request
|
||||
http_client = SimpleHttpClient(self.hs)
|
||||
uri = "%s/proxyValidate" % (self.cas_server_url,)
|
||||
args = {
|
||||
"ticket": login_submission["ticket"],
|
||||
"service": login_submission["service"]
|
||||
}
|
||||
body = yield http_client.get_raw(uri, args)
|
||||
body = yield self.http_client.get_raw(uri, args)
|
||||
result = yield self.do_cas_login(body)
|
||||
defer.returnValue(result)
|
||||
elif login_submission["type"] == LoginRestServlet.TOKEN_TYPE:
|
||||
|
|
Loading…
Reference in a new issue