Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Pass additional headers from the worker to the main process. #7797

Merged
merged 7 commits into from Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7797.bugfix
@@ -0,0 +1 @@
Fixes a long standing bug in worker mode where worker information was saved in the devices table instead of the original IP address and user agent.
14 changes: 10 additions & 4 deletions synapse/app/generic_worker.py
Expand Up @@ -206,10 +206,16 @@ async def on_POST(self, request, device_id):

if body:
# They're actually trying to upload something, proxy to main synapse.
# Pass through the auth headers, if any, in case the access token
# is there.
auth_headers = request.requestHeaders.getRawHeaders(b"Authorization", [])
headers = {"Authorization": auth_headers}

# Proxy headers from the original request, such as the auth headers
# (in case the access token is there) and the original IP /
# User-Agent of the request.
headers = {}
for header in (b"Authorization", b"X-Forwarded-For", b"User-Agent"):
header_value = request.requestHeaders.getRawHeaders(header)
if header_value:
headers[header] = header_value
clokep marked this conversation as resolved.
Show resolved Hide resolved

try:
result = await self.http_client.post_json_get_json(
self.main_uri + request.uri.decode("ascii"), body, headers=headers
Expand Down