Python3 SSL socket handling
This commit is contained in:
parent
0e33743293
commit
6e27ecfe8c
16
servefile
16
servefile
|
@ -13,6 +13,7 @@ import argparse
|
||||||
import base64
|
import base64
|
||||||
import cgi
|
import cgi
|
||||||
import datetime
|
import datetime
|
||||||
|
import io
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -771,8 +772,19 @@ class SecureThreadedHTTPServer(ThreadedHTTPServer):
|
||||||
class SecureHandler():
|
class SecureHandler():
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.connection = self.request
|
self.connection = self.request
|
||||||
self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
|
|
||||||
self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
|
if sys.version_info[0] > 2:
|
||||||
|
# python3 SocketIO (replacement for socket._fileobject)
|
||||||
|
raw_read_sock = socket.SocketIO(self.request, 'rb')
|
||||||
|
raw_write_sock = socket.SocketIO(self.request, 'wb')
|
||||||
|
rbufsize = self.rbufsize > 0 and self.rbufsize or io.DEFAULT_BUFFER_SIZE
|
||||||
|
wbufsize = self.wbufsize > 0 and self.wbufsize or io.DEFAULT_BUFFER_SIZE
|
||||||
|
self.rfile = io.BufferedReader(raw_read_sock, rbufsize)
|
||||||
|
self.wfile = io.BufferedWriter(raw_write_sock, wbufsize)
|
||||||
|
else:
|
||||||
|
# python2 does not have SocketIO
|
||||||
|
self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
|
||||||
|
self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
|
||||||
|
|
||||||
class ServeFileException(Exception):
|
class ServeFileException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -274,3 +274,13 @@ def test_https(run_servefile, datadir):
|
||||||
# assert fingerprint
|
# assert fingerprint
|
||||||
urllib3.disable_warnings()
|
urllib3.disable_warnings()
|
||||||
check_download(data, protocol='https', verify=False)
|
check_download(data, protocol='https', verify=False)
|
||||||
|
|
||||||
|
def test_https_big_download(run_servefile, datadir):
|
||||||
|
# test with about 10 mb of data
|
||||||
|
data = "x" * (10 * 1024 ** 2)
|
||||||
|
p = datadir({'testfile': data}) / 'testfile'
|
||||||
|
run_servefile(['--ssl', str(p)])
|
||||||
|
time.sleep(0.2) # time for generating ssl certificates
|
||||||
|
|
||||||
|
urllib3.disable_warnings()
|
||||||
|
check_download(data, protocol='https', verify=False)
|
||||||
|
|
Loading…
Reference in New Issue