forked from seba/servefile
				
			Fix exception on transmission abort with python3
With python3 sys.exc_value does no longer exist, but we can replace it with sys.exc_info().
This commit is contained in:
		
							parent
							
								
									11a7d8bd13
								
							
						
					
					
						commit
						058de2f39c
					
				|  | @ -2,6 +2,12 @@ servefile changelog | |||
| =================== | ||||
| 
 | ||||
| 
 | ||||
| Unreleased | ||||
| ---------- | ||||
| 
 | ||||
| 	* fixed bug where exception was shown on transmission abort with python3 | ||||
| 
 | ||||
| 
 | ||||
| 2020-10-30 v0.5.1 | ||||
| ----------------- | ||||
| 
 | ||||
|  |  | |||
|  | @ -714,7 +714,8 @@ class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler): | |||
| 
 | ||||
| class ThreadedHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): | ||||
| 	def handle_error(self, request, client_address): | ||||
| 		print("%s ABORTED transmission (Reason: %s)" % (client_address[0], sys.exc_value)) | ||||
| 		_, exc_value, _ = sys.exc_info() | ||||
| 		print("%s ABORTED transmission (Reason: %s)" % (client_address[0], exc_value)) | ||||
| 
 | ||||
| 
 | ||||
| def catchSSLErrors(BaseSSLClass): | ||||
|  |  | |||
|  | @ -356,3 +356,24 @@ def test_https_big_download(run_servefile, datadir): | |||
| 
 | ||||
|     urllib3.disable_warnings() | ||||
|     check_download(data, protocol='https', verify=False) | ||||
| 
 | ||||
| 
 | ||||
| def test_abort_download(run_servefile, datadir): | ||||
|     data = "x" * (10 * 1024 ** 2) | ||||
|     p = datadir({'testfile': data}) / 'testfile' | ||||
|     env = os.environ.copy() | ||||
|     env['PYTHONUNBUFFERED'] = '1' | ||||
|     proc = run_servefile(str(p), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) | ||||
| 
 | ||||
|     # provoke a connection abort | ||||
|     # hopefully the buffers will not fill up with all of the 10mb | ||||
|     sock = socket.socket(socket.AF_INET) | ||||
|     sock.connect(("localhost", 8080)) | ||||
|     sock.send(b"GET /testfile HTTP/1.0\n\n") | ||||
|     resp = sock.recv(100) | ||||
|     assert resp != b'' | ||||
|     sock.close() | ||||
|     time.sleep(0.1) | ||||
|     proc.kill() | ||||
|     out = proc.stdout.read().decode() | ||||
|     assert "127.0.0.1 ABORTED transmission" in out | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue