Still broken

This commit is contained in:
Andrew 2021-08-22 10:54:34 -04:00
parent 4ff0392292
commit 734a576cb9
4 changed files with 61 additions and 3 deletions

View File

@ -28,6 +28,7 @@ try:
from app.classes.web.static_handler import CustomStaticHandler
from app.classes.shared.translation import translation
from app.classes.web.upload_handler import UploadHandler
from app.classes.web.upload_handler import ProxyHandler
except ModuleNotFoundError as e:
logger.critical("Import Error: Unable to load {} module".format(e, e.name))
@ -131,6 +132,7 @@ class Webserver:
(r'/api/stats/node', NodeStats, handler_args),
(r'/ws', SocketHandler, handler_args),
(r'/upload', UploadHandler, handler_args),
(r'/proxy', ProxyHandler, handler_args)
]
app = tornado.web.Application(

View File

@ -7,6 +7,7 @@ from tornado.options import parse_command_line, define, options
from tornado.web import Application, RequestHandler, stream_request_body
import logging
import toro
logger = logging.getLogger(__name__)
@ -32,3 +33,56 @@ class UploadHandler(RequestHandler):
print("In PUT")
logger.info('UploadHandler.put')
self.write('ok')
@stream_request_body
class ProxyHandler(RequestHandler):
def prepare(self):
logger.info('ProxyHandler.prepare')
self.chunks = toro.Queue(1)
self.fetch_future = AsyncHTTPClient().fetch(
'http://localhost:%d/upload' % options.port,
method='PUT',
body_producer=self.body_producer,
request_timeout=3600.0)
@gen.coroutine
def body_producer(self, write):
while True:
chunk = yield self.chunks.get()
if chunk is None:
return
yield write(chunk)
@gen.coroutine
def data_received(self, chunk):
logger.info('ProxyHandler.data_received(%d bytes: %r)',
len(chunk), chunk[:9])
yield self.chunks.put(chunk)
@gen.coroutine
def put(self):
logger.info('ProxyHandler.put')
# Write None to the chunk queue to signal body_producer to exit,
# then wait for the request to finish.
yield self.chunks.put(None)
response = yield self.fetch_future
self.set_status(response.code)
self.write(response.body)
@gen.coroutine
def client():
@gen.coroutine
def body_producer(write):
for i in range(options.num_chunks):
yield gen.Task(IOLoop.current().call_later, options.client_delay)
chunk = ('chunk %02d ' % i) * 10000
logger.info('client writing %d bytes: %r', len(chunk), chunk[:9])
yield write(utf8(chunk))
response = yield AsyncHTTPClient().fetch(
'http://localhost:%d/proxy' % options.port,
method='PUT',
body_producer=body_producer,
request_timeout=3600.0)
logger.info('client finished with response %d: %r',
response.code, response.body)

View File

@ -548,12 +548,13 @@
files = document.getElementById("upload_files").files
for (i = 0; i < files.length; i++){
var xmlHttpRequest = new XMLHttpRequest();
var file = files[i]
var fileName = files[i].name
var target = '/upload'
var target = '/proxy'
var mimeType = files[i].type
xmlHttpRequest.open('PUT', target, true);
xmlHttpRequest.open('POSTT', target, true);
console.log(xmlHttpRequest);
xmlHttpRequest.setRequestHeader('Content-Type', mimeType);
xmlHttpRequest.setRequestHeader('Content-Disposition', 'attachment; filename="' + fileName + '"');

View File

@ -16,10 +16,11 @@ pyminifier==2.1
pyOpenSSL==19.1.0
pyparsing==2.4.7
PyYAML==5.3.1
requests==2.24.0
requests~=2.26.0
schedule==0.6.0
six==1.15.0
termcolor==1.1.0
tornado==6.0.4
urllib3==1.25.10
webencodings==0.5.1
toro~=1.0.1