Repaired websocket support.
This commit is contained in:
parent
6e5b159168
commit
19f8f938ff
@ -126,10 +126,9 @@ class Application:
|
|||||||
req_resp, headers = await self.get_headers(reader)
|
req_resp, headers = await self.get_headers(reader)
|
||||||
if not headers:
|
if not headers:
|
||||||
break
|
break
|
||||||
else:
|
if headers:
|
||||||
data = await reader.read()
|
|
||||||
if 'Content-Length' in headers:
|
if 'Content-Length' in headers:
|
||||||
while not len(data) == headers['Content-Length']:
|
while len(data) != headers['Content-Length']:
|
||||||
chunk_size = headers['Content-Length'] - len(data) if self.buffer_size > headers['Content-Length'] - len(data) else self.buffer_size
|
chunk_size = headers['Content-Length'] - len(data) if self.buffer_size > headers['Content-Length'] - len(data) else self.buffer_size
|
||||||
print("Bef read")
|
print("Bef read")
|
||||||
chunk = await reader.read(chunk_size)
|
chunk = await reader.read(chunk_size)
|
||||||
@ -138,11 +137,13 @@ class Application:
|
|||||||
break
|
break
|
||||||
print("Aff read")
|
print("Aff read")
|
||||||
data += chunk
|
data += chunk
|
||||||
print(self.header_dict_to_bytes(req_resp,headers).decode())
|
|
||||||
await writer.write(self.header_dict_to_bytes(req_resp, headers))
|
await writer.write(self.header_dict_to_bytes(req_resp, headers))
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
if data:
|
if data:
|
||||||
await writer.write(data)
|
await writer.write(data)
|
||||||
|
else:
|
||||||
|
data = await reader.read()
|
||||||
|
await writer.write(data)
|
||||||
#if not headers.get('Connection') == 'keep-alive': # and not headers.get('Upgrade-Insecure-Requests'):
|
#if not headers.get('Connection') == 'keep-alive': # and not headers.get('Upgrade-Insecure-Requests'):
|
||||||
# break
|
# break
|
||||||
break
|
break
|
||||||
@ -169,18 +170,18 @@ class Application:
|
|||||||
print(f"Connected to upstream #{self.total_connection_count} server {self.upstream_host}:{self.upstream_port} #{connection_nr} Time: {get_timestamp()}")
|
print(f"Connected to upstream #{self.total_connection_count} server {self.upstream_host}:{self.upstream_port} #{connection_nr} Time: {get_timestamp()}")
|
||||||
|
|
||||||
request_headers = await self.stream(reader, upstream_writer,is_websocket)
|
request_headers = await self.stream(reader, upstream_writer,is_websocket)
|
||||||
|
|
||||||
|
keep_alive = False
|
||||||
|
if request_headers:
|
||||||
|
if request_headers.get('Connection') == 'keep-alive': # and not headers.get('Upgrade-Insecure-Requests'):
|
||||||
|
keep_alive = True
|
||||||
|
if request_headers.get("Upgrade") == 'websocket':
|
||||||
|
is_websocket = True
|
||||||
await self.stream(upstream_reader, writer, is_websocket)
|
await self.stream(upstream_reader, writer, is_websocket)
|
||||||
time_end = time.time()
|
time_end = time.time()
|
||||||
time_duration = time_end - time_start
|
time_duration = time_end - time_start
|
||||||
print(f"Disconnected upstream #{self.total_connection_count} server {self.upstream_host}:{self.upstream_port} #{connection_nr} Duration: {time_duration:.5f}s")
|
print(f"Disconnected upstream #{self.total_connection_count} server {self.upstream_host}:{self.upstream_port} #{connection_nr} Duration: {time_duration:.5f}s")
|
||||||
|
|
||||||
keep_alive = False
|
|
||||||
|
|
||||||
if request_headers.get('Connection') == 'keep-alive': # and not headers.get('Upgrade-Insecure-Requests'):
|
|
||||||
keep_alive = True
|
|
||||||
|
|
||||||
if request_headers.get("Upgrade") == 'websocket':
|
|
||||||
is_websocket = True
|
|
||||||
|
|
||||||
if not any([keep_alive, is_websocket]):
|
if not any([keep_alive, is_websocket]):
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user