mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 09:06:06 -04:00
Allow synapse's useragent to be customized
This will allow me to write tests which verify which server made HTTP requests in a federation context.
This commit is contained in:
parent
301141515a
commit
8fc52bc56a
2 changed files with 10 additions and 6 deletions
|
@ -67,7 +67,9 @@ class SimpleHttpClient(object):
|
|||
connectTimeout=15,
|
||||
contextFactory=hs.get_http_client_context_factory()
|
||||
)
|
||||
self.version_string = hs.version_string
|
||||
self.user_agent = hs.config.user_agent_override
|
||||
if self.user_agent is None:
|
||||
self.user_agent = hs.version_string
|
||||
|
||||
def request(self, method, uri, *args, **kwargs):
|
||||
# A small wrapper around self.agent.request() so we can easily attach
|
||||
|
@ -112,7 +114,7 @@ class SimpleHttpClient(object):
|
|||
uri.encode("ascii"),
|
||||
headers=Headers({
|
||||
b"Content-Type": [b"application/x-www-form-urlencoded"],
|
||||
b"User-Agent": [self.version_string],
|
||||
b"User-Agent": [self.user_agent],
|
||||
}),
|
||||
bodyProducer=FileBodyProducer(StringIO(query_bytes))
|
||||
)
|
||||
|
@ -131,7 +133,8 @@ class SimpleHttpClient(object):
|
|||
"POST",
|
||||
uri.encode("ascii"),
|
||||
headers=Headers({
|
||||
"Content-Type": ["application/json"]
|
||||
b"Content-Type": [b"application/json"],
|
||||
b"User-Agent": [self.user_agent],
|
||||
}),
|
||||
bodyProducer=FileBodyProducer(StringIO(json_str))
|
||||
)
|
||||
|
@ -165,7 +168,7 @@ class SimpleHttpClient(object):
|
|||
"GET",
|
||||
uri.encode("ascii"),
|
||||
headers=Headers({
|
||||
b"User-Agent": [self.version_string],
|
||||
b"User-Agent": [self.user_agent],
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -206,7 +209,7 @@ class SimpleHttpClient(object):
|
|||
"PUT",
|
||||
uri.encode("ascii"),
|
||||
headers=Headers({
|
||||
b"User-Agent": [self.version_string],
|
||||
b"User-Agent": [self.user_agent],
|
||||
"Content-Type": ["application/json"]
|
||||
}),
|
||||
bodyProducer=FileBodyProducer(StringIO(json_str))
|
||||
|
@ -241,7 +244,7 @@ class CaptchaServerHttpClient(SimpleHttpClient):
|
|||
bodyProducer=FileBodyProducer(StringIO(query_bytes)),
|
||||
headers=Headers({
|
||||
b"Content-Type": [b"application/x-www-form-urlencoded"],
|
||||
b"User-Agent": [self.version_string],
|
||||
b"User-Agent": [self.user_agent],
|
||||
})
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue