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
693d0b8f
Commit
693d0b8f
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Replace on_send_callback with something a bit clearer so that we can sign messages
parent
66df7f1a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/http/client.py
+35
-11
35 additions, 11 deletions
synapse/http/client.py
with
35 additions
and
11 deletions
synapse/http/client.py
+
35
−
11
View file @
693d0b8f
...
...
@@ -31,6 +31,7 @@ from StringIO import StringIO
import
json
import
logging
import
urllib
import
urlparse
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -68,16 +69,20 @@ class BaseHttpClient(object):
self
.
hs
=
hs
@defer.inlineCallbacks
def
_create_request
(
self
,
destination
,
method
,
path_bytes
,
param_bytes
=
b
""
,
query_bytes
=
b
""
,
producer
=
None
,
headers_dict
=
{},
retry_on_dns_fail
=
True
,
on_send_callback
=
None
):
def
_create_request
(
self
,
destination
,
method
,
path_bytes
,
body_callback
,
headers_dict
=
{},
param_bytes
=
b
""
,
query_bytes
=
b
""
,
retry_on_dns_fail
=
True
):
"""
Creates and sends a request to the given url
"""
headers_dict
[
b
"
User-Agent
"
]
=
[
b
"
Synapse
"
]
headers_dict
[
b
"
Host
"
]
=
[
destination
]
logger
.
debug
(
"
Sending request to %s: %s %s;%s?%s
"
,
destination
,
method
,
path_bytes
,
param_bytes
,
query_bytes
)
url_bytes
=
urlparse
.
urlunparse
(
(
""
,
""
,
path_bytes
,
param_bytes
,
query_bytes
,
""
,)
)
logger
.
debug
(
"
Sending request to %s: %s %s
"
,
destination
,
method
,
url_bytes
)
logger
.
debug
(
"
Types: %s
"
,
...
...
@@ -93,8 +98,8 @@ class BaseHttpClient(object):
endpoint
=
self
.
_getEndpoint
(
reactor
,
destination
);
while
True
:
if
on_send_callback
:
on_send_callback
(
destination
,
method
,
path
_bytes
,
producer
)
producer
=
body_callback
(
method
,
url
_bytes
,
headers_dict
)
try
:
response
=
yield
self
.
agent
.
request
(
...
...
@@ -167,13 +172,22 @@ class MatrixHttpClient(BaseHttpClient):
will be the decoded JSON body. On a 4xx or 5xx error response a
CodeMessageException is raised.
"""
if
not
on_send_callback
:
def
on_send_callback
(
destination
,
method
,
path_bytes
,
producer
):
pass
def
body_callback
(
method
,
url_bytes
,
headers_dict
):
producer
=
_JsonProducer
(
data
)
on_send_callback
(
destination
,
method
,
path
,
producer
)
return
producer
response
=
yield
self
.
_create_request
(
destination
.
encode
(
"
ascii
"
),
"
PUT
"
,
path
.
encode
(
"
ascii
"
),
producer
=
_JsonProducer
(
data
)
,
body_callback
=
body_callback
,
headers_dict
=
{
"
Content-Type
"
:
[
"
application/json
"
]},
on_send_callback
=
on_send_callback
,
)
logger
.
debug
(
"
Getting resp body
"
)
...
...
@@ -206,11 +220,15 @@ class MatrixHttpClient(BaseHttpClient):
query_bytes
=
urllib
.
urlencode
(
args
,
True
)
logger
.
debug
(
"
Query bytes: %s Retry DNS: %s
"
,
args
,
retry_on_dns_fail
)
def
body_callback
(
method
,
url_bytes
,
headers_dict
):
return
None
response
=
yield
self
.
_create_request
(
destination
.
encode
(
"
ascii
"
),
"
GET
"
,
path
.
encode
(
"
ascii
"
),
query_bytes
=
query_bytes
,
body_callback
=
body_callback
,
retry_on_dns_fail
=
retry_on_dns_fail
)
...
...
@@ -239,11 +257,14 @@ class IdentityServerHttpClient(BaseHttpClient):
logger
.
debug
(
"
post_urlencoded_get_json args: %s
"
,
args
)
query_bytes
=
urllib
.
urlencode
(
args
,
True
)
def
body_callback
(
method
,
url_bytes
,
headers_dict
):
return
FileBodyProducer
(
StringIO
(
query_bytes
))
response
=
yield
self
.
_create_request
(
destination
.
encode
(
"
ascii
"
),
"
POST
"
,
path
.
encode
(
"
ascii
"
),
producer
=
FileBodyProducer
(
StringIO
(
query_bytes
))
,
body_callback
=
body_callback
,
headers_dict
=
{
"
Content-Type
"
:
[
"
application/x-www-form-urlencoded
"
]
}
...
...
@@ -265,11 +286,14 @@ class CaptchaServerHttpClient(MatrixHttpClient):
args
=
{}):
query_bytes
=
urllib
.
urlencode
(
args
,
True
)
def
body_callback
(
method
,
url_bytes
,
headers_dict
):
return
FileBodyProducer
(
StringIO
(
query_bytes
))
response
=
yield
self
.
_create_request
(
destination
.
encode
(
"
ascii
"
),
"
POST
"
,
path
.
encode
(
"
ascii
"
),
producer
=
FileBodyProducer
(
StringIO
(
query_bytes
))
,
body_callback
=
body_callback
,
headers_dict
=
{
"
Content-Type
"
:
[
"
application/x-www-form-urlencoded
"
]
}
...
...
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