Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
37b2d69b
Commit
37b2d69b
authored
9 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Reuse a single http client, rather than creating new ones
parent
5eb4d13a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/handlers/identity.py
+5
-9
5 additions, 9 deletions
synapse/handlers/identity.py
synapse/push/httppusher.py
+3
-4
3 additions, 4 deletions
synapse/push/httppusher.py
synapse/rest/client/v1/login.py
+2
-5
2 additions, 5 deletions
synapse/rest/client/v1/login.py
with
10 additions
and
18 deletions
synapse/handlers/identity.py
+
5
−
9
View file @
37b2d69b
...
...
@@ -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
"
...
...
This diff is collapsed.
Click to expand it.
synapse/push/httppusher.py
+
3
−
4
View file @
37b2d69b
...
...
@@ -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
.
http
Cli
=
S
imple
H
ttp
C
lient
(
self
.
hs
)
self
.
http
_client
=
_hs
.
get_s
imple
_h
ttp
_c
lient
()
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
.
http
Cli
.
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
.
http
Cli
.
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
)
...
...
This diff is collapsed.
Click to expand it.
synapse/rest/client/v1/login.py
+
2
−
5
View file @
37b2d69b
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment