Skip to content

Commit a7ba331

Browse files
committed
Refs #262. Removed twisted form handler on file POST requests
1 parent dc53b24 commit a7ba331

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

teraserver/python/config/opentera.conf

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ location /log/ {
3939

4040
location /file/ {
4141
client_max_body_size 500M;
42+
proxy_buffering off;
43+
proxy_request_buffering off;
4244
proxy_pass http://127.0.0.1:4042/;
4345
proxy_redirect http://$host/ https://$host:$server_port/;
4446
proxy_set_header X-ExternalPort $server_port;

teraserver/python/services/FileTransferService/FlaskModule.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
# Twisted
1414
from twisted.internet import reactor
15-
from twisted.web.http import HTTPChannel
16-
from twisted.web.server import Site
15+
from twisted.web.http import HTTPChannel, parse_qs
16+
from twisted.web.server import Site, Request
1717
from twisted.web.static import File
1818
from twisted.web.wsgi import WSGIResource
1919
import os
@@ -85,6 +85,27 @@ class MySite(Site):
8585
def __init__(self, resource, requestFactory=None, *args, **kwargs):
8686
super().__init__(resource, requestFactory, *args, **kwargs)
8787

88+
class MyRequest(Request):
89+
def requestReceived(self, command, path, version):
90+
# print('Request received', command, path, version)
91+
if command == b"POST" and path == b"/api/assets":
92+
self.content.seek(0, 0)
93+
self.args = {}
94+
95+
self.method, self.uri = command, path
96+
self.clientproto = version
97+
x = self.uri.split(b"?", 1)
98+
99+
if len(x) == 1:
100+
self.path = self.uri
101+
else:
102+
self.path, argstring = x
103+
self.args = parse_qs(argstring, 1)
104+
105+
super().process()
106+
else:
107+
super().requestReceived(command, path, version)
108+
88109

89110
# Simple fix for API documentation used with reverse proxy
90111
class CustomAPI(Api):
@@ -169,6 +190,7 @@ def __init__(self, config: ConfigManager):
169190
flask_app.config.update({'BABEL_DEFAULT_LOCALE': 'fr'})
170191
flask_app.config.update({'SESSION_COOKIE_SECURE': True})
171192
flask_app.config.update({'PROPAGATE_EXCEPTIONS': True})
193+
# flask_app.config.update({'USE_X_SENDFILE': True})
172194

173195
# TODO set upload folder in config
174196
flask_app.config.update({'UPLOAD_FOLDER': config.filetransfer_config['files_directory']})
@@ -199,6 +221,7 @@ def create_service(self):
199221

200222
# Create a Twisted Web Site
201223
site = MySite(root_resource)
224+
site.requestFactory = MyRequest
202225
# val = internet.TCPServer(self.config.service_config['port'], site)
203226
val = reactor.listenTCP(self.config.service_config['port'], site)
204227
return val

0 commit comments

Comments
 (0)