mirror of
https://github.com/DragonMinded/bemaniutils.git
synced 2026-04-26 01:45:17 -05:00
Merge pull request #3 from DragonMinded/alt_proxy_fix
Be more precise about headers sent during proxy
This commit is contained in:
commit
2e92e45ae6
|
|
@ -99,6 +99,7 @@ def receive_request(path: str) -> Response:
|
||||||
remote_address = request.headers.get('X-Remote-Address', None)
|
remote_address = request.headers.get('X-Remote-Address', None)
|
||||||
request_compression = request.headers.get('X-Compress', None)
|
request_compression = request.headers.get('X-Compress', None)
|
||||||
request_encryption = request.headers.get('X-Eamuse-Info', None)
|
request_encryption = request.headers.get('X-Eamuse-Info', None)
|
||||||
|
request_client = request.headers.get('User-Agent', None)
|
||||||
|
|
||||||
actual_path = f'/{path}'
|
actual_path = f'/{path}'
|
||||||
if request.query_string is not None and len(request.query_string) > 0:
|
if request.query_string is not None and len(request.query_string) > 0:
|
||||||
|
|
@ -153,24 +154,33 @@ def receive_request(path: str) -> Response:
|
||||||
client_proto.last_packet_encoding,
|
client_proto.last_packet_encoding,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set up custom headers for remote request
|
# Set up custom headers for remote request.
|
||||||
headers = {}
|
headers = {
|
||||||
|
# For lobby functionality, make sure the request receives
|
||||||
|
# the original IP address
|
||||||
|
'X-Remote-Address': remote_address or request.remote_addr,
|
||||||
|
# Some remote servers can be somewhat buggy, so we make sure
|
||||||
|
# to specify a range of encodings.
|
||||||
|
'Accept-Encoding': 'identity, deflate, compress, gzip',
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy over required headers that are sent by game client.
|
||||||
if request_compression is not None:
|
if request_compression is not None:
|
||||||
headers['X-Compress'] = request_compression
|
headers['X-Compress'] = request_compression
|
||||||
if request_encryption is not None:
|
if request_encryption is not None:
|
||||||
headers['X-Eamuse-Info'] = request_encryption
|
headers['X-Eamuse-Info'] = request_encryption
|
||||||
|
if request_client is not None:
|
||||||
# For lobby functionality, make sure the request receives
|
headers['User-Agent'] = request_client
|
||||||
# the original IP address
|
|
||||||
headers['X-Remote-Address'] = remote_address or request.remote_addr
|
|
||||||
|
|
||||||
# Make request to foreign service, using the same parameters
|
# Make request to foreign service, using the same parameters
|
||||||
r = requests.post(
|
prep_req = requests.Request(
|
||||||
f'http://{remote_host}:{remote_port}{actual_path}',
|
'POST',
|
||||||
|
url=f'http://{remote_host}:{remote_port}{actual_path}',
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data=req_binary,
|
data=req_binary,
|
||||||
timeout=config['timeout'],
|
).prepare()
|
||||||
)
|
sess = requests.Session()
|
||||||
|
r = sess.send(prep_req, timeout=config['timeout']) # type: ignore
|
||||||
|
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
# Failed on remote side
|
# Failed on remote side
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user