|
12 | 12 |
|
13 | 13 | # Twisted
|
14 | 14 | 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 |
17 | 17 | from twisted.web.static import File
|
18 | 18 | from twisted.web.wsgi import WSGIResource
|
19 | 19 | import os
|
@@ -85,6 +85,27 @@ class MySite(Site):
|
85 | 85 | def __init__(self, resource, requestFactory=None, *args, **kwargs):
|
86 | 86 | super().__init__(resource, requestFactory, *args, **kwargs)
|
87 | 87 |
|
| 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 | + |
88 | 109 |
|
89 | 110 | # Simple fix for API documentation used with reverse proxy
|
90 | 111 | class CustomAPI(Api):
|
@@ -169,6 +190,7 @@ def __init__(self, config: ConfigManager):
|
169 | 190 | flask_app.config.update({'BABEL_DEFAULT_LOCALE': 'fr'})
|
170 | 191 | flask_app.config.update({'SESSION_COOKIE_SECURE': True})
|
171 | 192 | flask_app.config.update({'PROPAGATE_EXCEPTIONS': True})
|
| 193 | + # flask_app.config.update({'USE_X_SENDFILE': True}) |
172 | 194 |
|
173 | 195 | # TODO set upload folder in config
|
174 | 196 | flask_app.config.update({'UPLOAD_FOLDER': config.filetransfer_config['files_directory']})
|
@@ -199,6 +221,7 @@ def create_service(self):
|
199 | 221 |
|
200 | 222 | # Create a Twisted Web Site
|
201 | 223 | site = MySite(root_resource)
|
| 224 | + site.requestFactory = MyRequest |
202 | 225 | # val = internet.TCPServer(self.config.service_config['port'], site)
|
203 | 226 | val = reactor.listenTCP(self.config.service_config['port'], site)
|
204 | 227 | return val
|
|
0 commit comments