wslink 2.0.4__py3-none-any.whl → 2.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
- import asyncio
2
1
  import os
3
2
  import logging
4
3
  import sys
5
4
  import uuid
5
+ import json
6
+ from pathlib import Path
6
7
 
7
8
  from wslink.protocol import WslinkHandler, AbstractWebApp
8
9
 
@@ -12,8 +13,13 @@ import aiohttp.web as aiohttp_web
12
13
 
13
14
 
14
15
  # 4MB is the default inside aiohttp
16
+ MSG_OVERHEAD = int(os.environ.get("WSLINK_MSG_OVERHEAD", 4096))
15
17
  MAX_MSG_SIZE = int(os.environ.get("WSLINK_MAX_MSG_SIZE", 4194304))
16
18
  HEART_BEAT = int(os.environ.get("WSLINK_HEART_BEAT", 30)) # 30 seconds
19
+ HTTP_HEADERS: str | None = os.environ.get("WSLINK_HTTP_HEADERS") # path to json file
20
+
21
+ if HTTP_HEADERS and Path(HTTP_HEADERS).exists():
22
+ HTTP_HEADERS: dict = json.loads(Path(HTTP_HEADERS).read_text())
17
23
 
18
24
  logger = logging.getLogger(__name__)
19
25
 
@@ -34,17 +40,13 @@ def _fix_path(path):
34
40
  return path
35
41
 
36
42
 
37
- # -----------------------------------------------------------------------------
38
- # Needed for WASM/sharedArrayBuffer
39
- # => we should find a way to dynamically provided needed header
40
43
  # -----------------------------------------------------------------------------
41
44
  @aiohttp_web.middleware
42
- async def shared_array_buffer_headers(request: aiohttp_web.Request, handler):
45
+ async def http_headers(request: aiohttp_web.Request, handler):
43
46
  response: aiohttp_web.Response = await handler(request)
44
- response.headers.setdefault("Cross-Origin-Opener-Policy", "same-origin")
45
- response.headers.setdefault("Cross-Origin-Embedder-Policy", "require-corp")
46
- response.headers.setdefault("Access-Control-Allow-Origin", "*")
47
- response.headers.setdefault("Cache-Control", "no-store")
47
+ for k, v in HTTP_HEADERS.items():
48
+ response.headers.setdefault(k, v)
49
+
48
50
  return response
49
51
 
50
52
 
@@ -52,7 +54,10 @@ async def shared_array_buffer_headers(request: aiohttp_web.Request, handler):
52
54
  class WebAppServer(AbstractWebApp):
53
55
  def __init__(self, server_config):
54
56
  AbstractWebApp.__init__(self, server_config)
55
- self.set_app(aiohttp_web.Application(middlewares=[shared_array_buffer_headers]))
57
+ if HTTP_HEADERS:
58
+ self.set_app(aiohttp_web.Application(middlewares=[http_headers]))
59
+ else:
60
+ self.set_app(aiohttp_web.Application())
56
61
  self._ws_handlers = []
57
62
  self._site = None
58
63
  self._runner = None
@@ -212,7 +217,7 @@ class AioHttpWsHandler(WslinkHandler):
212
217
  async def handleWsRequest(self, request):
213
218
  client_id = str(uuid.uuid4()).replace("-", "")
214
219
  current_ws = aiohttp_web.WebSocketResponse(
215
- max_msg_size=MAX_MSG_SIZE, heartbeat=HEART_BEAT
220
+ max_msg_size=MSG_OVERHEAD + MAX_MSG_SIZE, heartbeat=HEART_BEAT
216
221
  )
217
222
  self.connections[client_id] = current_ws
218
223
 
wslink/protocol.py CHANGED
@@ -252,6 +252,7 @@ class WslinkHandler(object):
252
252
 
253
253
  async def onMessage(self, is_binary, msg, client_id):
254
254
  if not is_binary:
255
+ logger.critical("wslink is not expecting text message:\n> %s", msg.data)
255
256
  return
256
257
 
257
258
  full_message = self.unchunkers[client_id].process_chunk(msg.data)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wslink
3
- Version: 2.0.4
3
+ Version: 2.1.0
4
4
  Summary: Python/JavaScript library for communicating over WebSocket
5
5
  Home-page: https://github.com/kitware/wslink
6
6
  Author: Kitware, Inc.
@@ -65,6 +65,7 @@ Those only apply for the Python server and launcher.
65
65
  * WSLINK_LAUNCHER_DELETE - If set to 1 this will enable the DELETE endpoint for killing a running session
66
66
  * WSLINK_MAX_MSG_SIZE - Number of bytes for a message size (default: 4194304)
67
67
  * WSLINK_HEART_BEAT - Number of seconds between heartbeats (default: 30)
68
+ * WSLINK_HTTP_HEADERS - Path to json file containing HTTP headers to be added
68
69
 
69
70
  License
70
71
  -------
@@ -2,7 +2,7 @@ wslink/LICENSE,sha256=I44UH7kDVqxDLnnlOWw_hFL2Fz7RjQ_4vPzZv9NYgTU,1483
2
2
  wslink/__init__.py,sha256=7Uyn6lk5LhykHbBwQ9pwSmX1YhxDanD9TT6H95DXzhk,2709
3
3
  wslink/chunking.py,sha256=1DJlGG6fjknGFrqPOtqUUc5tCrijldP7Kdx56d5e3Wg,7337
4
4
  wslink/launcher.py,sha256=8VMs3juObLkyGYQFNLjMoo4qFpKIcxWz0kS-af-DKO4,21170
5
- wslink/protocol.py,sha256=zdf4QthFHpAgEw3hTUyyaOuN76jzHeOJBpvekPbk7aY,15886
5
+ wslink/protocol.py,sha256=V5kqfHebfyXzmZq0-ua0SjDkOXdQmx1Mu29G3hORgx0,15971
6
6
  wslink/publish.py,sha256=9G5TXqyGr-LCo_LwHYhzif6lhG2iXDvEBmEgwR8fh1M,1437
7
7
  wslink/relay.py,sha256=E8Lzu2Ay7KbOheN1-ArAZawo8lLqdDgJXOZSBuMknYs,86
8
8
  wslink/server.py,sha256=yvhCjpzPOfhbZrpDvW9i4H_uSyuQAe3ZOP-BRBmgHQA,9326
@@ -10,7 +10,7 @@ wslink/ssl_context.py,sha256=hNOJJCdrStws1Qf6vPvY4vTk9Bf8J5d90W3fS0cRv8o,2290
10
10
  wslink/uri.py,sha256=woCQ4yChUqTMg9IT6YYDtUYeKmCg7OUCEgeBGA-19DY,384
11
11
  wslink/websocket.py,sha256=pBiWqkL8Zn8LuSJ9nv3yA-KjEynbolOQ2gLHtQFJ2Ic,4611
12
12
  wslink/backends/__init__.py,sha256=cyJGjm-YyBSyOEX81owyTbJ3YnrA6dB7--B4LnsEtHI,1214
13
- wslink/backends/aiohttp/__init__.py,sha256=sXCL6kI1Ilv_t2V3o6c8fKDcIJ0A3WaB2mwyPrXSM7E,9232
13
+ wslink/backends/aiohttp/__init__.py,sha256=RlQmJ7PgTUfCkBevpMPKquOfALdljOtGR7mWItdrcGI,9217
14
14
  wslink/backends/aiohttp/launcher.py,sha256=gHNMvtgNHEwBN_QBRDSCrTp2B4K1PsfV81rKaHi7Cxo,8897
15
15
  wslink/backends/aiohttp/relay.py,sha256=oZAzIQTpsQaObWXaa-_VtoTOUQALC_QLDd9UvWspYaU,13311
16
16
  wslink/backends/generic/__init__.py,sha256=Qu65gWsd2xCSsxybnDtEDI5vMjHN-F5jgPZOyNIxnGs,112
@@ -19,7 +19,7 @@ wslink/backends/jupyter/__init__.py,sha256=Qu65gWsd2xCSsxybnDtEDI5vMjHN-F5jgPZOy
19
19
  wslink/backends/jupyter/core.py,sha256=PCQN-uZPFROnRv8B5dNwnwHV67o4Bpme3_Z6V-zbOUA,3864
20
20
  wslink/backends/tornado/__init__.py,sha256=Qu65gWsd2xCSsxybnDtEDI5vMjHN-F5jgPZOyNIxnGs,112
21
21
  wslink/backends/tornado/core.py,sha256=tPMkkhWuO_ovkisVim0zcegwZKEAG4IRUdd_O_0a_R0,2157
22
- wslink-2.0.4.dist-info/METADATA,sha256=fTgpqrNfE65VXr09MwvMEd_McVQ1FmHWl5YCYK2iPEM,3045
23
- wslink-2.0.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
24
- wslink-2.0.4.dist-info/top_level.txt,sha256=N0d8eqvhwhfW1p1yPTmvxlbzhjz7ZyhBfysNvaFqpQY,7
25
- wslink-2.0.4.dist-info/RECORD,,
22
+ wslink-2.1.0.dist-info/METADATA,sha256=af9xY0D0eOaXmF02cMqoIAKfM8sQR7tl96vcoq_Dicw,3123
23
+ wslink-2.1.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
24
+ wslink-2.1.0.dist-info/top_level.txt,sha256=N0d8eqvhwhfW1p1yPTmvxlbzhjz7ZyhBfysNvaFqpQY,7
25
+ wslink-2.1.0.dist-info/RECORD,,
File without changes