comparison libervia/server/proxy.py @ 1360:389a83eefe62

server: SàT applications integration: - a SàT Application can be added to the menu (if necessary values are exposed), by using the `sat-app:[application_name]` in `menu_json` or `menu_extra_json`. The application will then be started with Libervia, and embedded, i.e. Libervia menu will appear and application will be integrated under it. - the same `sat-app:[application_name]` thing can be used in redirection, in this case the redirection will reverse proxy directly the application, without embedding it (no Libervia menu will appear) - the ReverseProxy will replace headers if necessary to allow embedding in a iframe from the same domain - new `embed_app` page to embed a SàT Application
author Goffi <goffi@goffi.org>
date Mon, 28 Sep 2020 21:12:21 +0200
parents
children 822bd0139769
comparison
equal deleted inserted replaced
1359:2da573bf3f8b 1360:389a83eefe62
1 #!/usr/bin/env python3
2
3 # Libervia: a Salut à Toi frontend
4 # Copyright (C) 2011-2020 Jérôme Poisson <goffi@goffi.org>
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from twisted.web import proxy
19 from twisted.python.compat import urlquote
20 from sat.core.log import getLogger
21
22 log = getLogger(__name__)
23
24
25
26 class SatProxyClient(proxy.ProxyClient):
27
28 def handleHeader(self, key, value):
29 if key.lower() == b"x-frame-options":
30 value = b"sameorigin"
31 elif key.lower() == b"content-security-policy":
32 value = value.replace(b"frame-ancestors 'none'", b"frame-ancestors 'self'")
33
34 super().handleHeader(key, value)
35
36
37 class SatProxyClientFactory(proxy.ProxyClientFactory):
38 protocol = SatProxyClient
39
40
41 class SatReverseProxyResource(proxy.ReverseProxyResource):
42 """Resource Proxy rewritting headers to allow embedding in iframe on same domain"""
43 proxyClientFactoryClass = SatProxyClientFactory
44
45 def getChild(self, path, request):
46 return SatReverseProxyResource(
47 self.host, self.port,
48 self.path + b'/' + urlquote(path, safe=b"").encode('utf-8'),
49 self.reactor
50 )