mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix sendfile with SSL
This commit is contained in:
parent
28d6d4be42
commit
7d10d8638f
@ -76,7 +76,7 @@ def proxy_environ(req):
|
|||||||
|
|
||||||
|
|
||||||
def create(req, sock, client, server, cfg):
|
def create(req, sock, client, server, cfg):
|
||||||
resp = Response(req, sock)
|
resp = Response(req, sock, cfg)
|
||||||
|
|
||||||
environ = default_environ(req, sock, cfg)
|
environ = default_environ(req, sock, cfg)
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ def create(req, sock, client, server, cfg):
|
|||||||
|
|
||||||
class Response(object):
|
class Response(object):
|
||||||
|
|
||||||
def __init__(self, req, sock):
|
def __init__(self, req, sock, cfg):
|
||||||
self.req = req
|
self.req = req
|
||||||
self.sock = sock
|
self.sock = sock
|
||||||
self.version = SERVER_SOFTWARE
|
self.version = SERVER_SOFTWARE
|
||||||
@ -186,6 +186,7 @@ class Response(object):
|
|||||||
self.response_length = None
|
self.response_length = None
|
||||||
self.sent = 0
|
self.sent = 0
|
||||||
self.upgrade = False
|
self.upgrade = False
|
||||||
|
self.cfg = cfg
|
||||||
|
|
||||||
def force_close(self):
|
def force_close(self):
|
||||||
self.must_close = True
|
self.must_close = True
|
||||||
@ -330,6 +331,23 @@ class Response(object):
|
|||||||
while sent != nbytes:
|
while sent != nbytes:
|
||||||
sent += sendfile(sockno, fileno, offset + sent, nbytes - sent)
|
sent += sendfile(sockno, fileno, offset + sent, nbytes - sent)
|
||||||
|
|
||||||
|
def sendfile_use_send(self, fileno, fo_offset, nbytes):
|
||||||
|
|
||||||
|
# send file in blocks of 8182 bytes
|
||||||
|
BLKSIZE = 8192
|
||||||
|
|
||||||
|
sent = 0
|
||||||
|
while sent != nbytes:
|
||||||
|
data = os.read(fileno, BLKSIZE)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
|
||||||
|
sent += len(data)
|
||||||
|
if sent > nbytes:
|
||||||
|
data = data[:nbytes-sent]
|
||||||
|
|
||||||
|
util.write(self.sock, data, self.chunked)
|
||||||
|
|
||||||
def write_file(self, respiter):
|
def write_file(self, respiter):
|
||||||
if sendfile is not None and util.is_fileobject(respiter.filelike):
|
if sendfile is not None and util.is_fileobject(respiter.filelike):
|
||||||
# sometimes the fileno isn't a callable
|
# sometimes the fileno isn't a callable
|
||||||
@ -350,14 +368,17 @@ class Response(object):
|
|||||||
|
|
||||||
self.send_headers()
|
self.send_headers()
|
||||||
|
|
||||||
if self.is_chunked():
|
if self.cfg.is_ssl:
|
||||||
chunk_size = "%X\r\n" % nbytes
|
self.sendfile_use_send(fileno, fo_offset, nbytes)
|
||||||
self.sock.sendall(chunk_size.encode('utf-8'))
|
else:
|
||||||
|
if self.is_chunked():
|
||||||
|
chunk_size = "%X\r\n" % nbytes
|
||||||
|
self.sock.sendall(chunk_size.encode('utf-8'))
|
||||||
|
|
||||||
self.sendfile_all(fileno, self.sock.fileno(), fo_offset, nbytes)
|
self.sendfile_all(fileno, self.sock.fileno(), fo_offset, nbytes)
|
||||||
|
|
||||||
if self.is_chunked():
|
if self.is_chunked():
|
||||||
self.sock.sendall(b"\r\n")
|
self.sock.sendall(b"\r\n")
|
||||||
|
|
||||||
os.lseek(fileno, fd_offset, os.SEEK_SET)
|
os.lseek(fileno, fd_offset, os.SEEK_SET)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user