mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
conn. keep-alive
This commit is contained in:
parent
78c99e524b
commit
75cae0261f
|
@ -30,12 +30,18 @@ class HttpCli(object):
|
|||
self.log_func(self.log_src, msg)
|
||||
|
||||
def run(self):
|
||||
while self.ok:
|
||||
headerlines = self.read_header()
|
||||
if not self.ok:
|
||||
return
|
||||
|
||||
self.headers = {}
|
||||
try:
|
||||
mode, self.req, _ = headerlines[0].split(" ")
|
||||
except:
|
||||
self.log("bad headers:\n" + "\n".join(headerlines))
|
||||
self.s.close()
|
||||
return
|
||||
|
||||
for header_line in headerlines[1:]:
|
||||
k, v = header_line.split(":", 1)
|
||||
|
@ -79,7 +85,7 @@ class HttpCli(object):
|
|||
return ret[:-4].decode("utf-8", "replace").split("\r\n")
|
||||
|
||||
def reply(self, body):
|
||||
header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {0}\r\n\r\n".format(
|
||||
header = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\nContent-Length: {0}\r\n\r\n".format(
|
||||
len(body)
|
||||
).encode(
|
||||
"utf-8"
|
||||
|
@ -87,7 +93,6 @@ class HttpCli(object):
|
|||
if self.ok:
|
||||
self.s.send(header + body)
|
||||
|
||||
self.s.close()
|
||||
return body
|
||||
|
||||
def loud_reply(self, body):
|
||||
|
@ -188,6 +193,15 @@ class HttpCli(object):
|
|||
).encode("utf-8")
|
||||
)
|
||||
|
||||
try:
|
||||
# TODO: check if actually part of multipart footer
|
||||
buf = self.sr.recv(2)
|
||||
if buf != b"\r\n":
|
||||
raise Exception("oh")
|
||||
except:
|
||||
self.log("client is done")
|
||||
self.s.close()
|
||||
|
||||
def handle_multipart(self, ofd):
|
||||
tlen = 0
|
||||
hashobj = hashlib.sha512()
|
||||
|
|
|
@ -200,12 +200,16 @@ class MpSrv(object):
|
|||
proc.workload += 50
|
||||
|
||||
def debug_load_balancer(self):
|
||||
while True:
|
||||
last = ""
|
||||
while self.procs:
|
||||
msg = ""
|
||||
for proc in self.procs:
|
||||
msg += "{} \033[36m{}\033[0m ".format(
|
||||
msg += "\033[1m{}\033[0;36m{:4}\033[0m ".format(
|
||||
len(proc.clients), proc.workload
|
||||
)
|
||||
|
||||
if msg != last:
|
||||
last = msg
|
||||
print(msg)
|
||||
|
||||
time.sleep(0.1)
|
||||
|
|
Loading…
Reference in a new issue