Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions VERSIONS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,8 @@
3.0.20220626 - Sun Jun 26 11:57:38 PDT 2022
* Fix RawSocket connections when recv returns fewer bytes than wanted
* Add SSL RawSocket support

3.0.20220909 - Fri Sep 9 12:04:34 PDT 2022
* Ensure agent string doesn't get forced to `swampyer-1.0`
* Now can supply an `agent` argument to `WAMPClient` that can be a simple string but also:
agent="myapp-1.2-{platform}" (which will send the platform info)
15 changes: 13 additions & 2 deletions swampyer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import json
import time
import ctypes
import platform
import threading
import traceback
import six
from six.moves import queue
from importlib.metadata import version

import socket

Expand Down Expand Up @@ -138,7 +140,7 @@ def __init__(
self,
url='ws://localhost:8080',
realm='realm1',
agent='python-swampyer-1.0',
agent=None,
uri_base='',
authmethods=None,
authid=None,
Expand All @@ -160,6 +162,14 @@ def __init__(

self._state = STATE_DISCONNECTED

# Set up the agent string used in the WAMP hellos
if agent is None:
agent = "python-swampyer-{swampyer_version}-{platform}"
agent = agent.format(
platform = platform.platform(),
swampyer_version = version('swampyer'),
)

super(WAMPClient,self).__init__()
self.daemon = True
self._request_loop_notify_restart = threading.Condition()
Expand Down Expand Up @@ -203,6 +213,7 @@ def connect(self,soft_reset=False,**options):
options.setdefault('sslopt',self.sslopt)
options.setdefault('loop_timeout',self.loop_timeout)
options.setdefault('serializers',self.serializers)
options.setdefault('agent', self.agent)

# Attempt connection once unless it's autoreconnect in which
# case we try and try again...
Expand Down Expand Up @@ -500,7 +511,7 @@ def hello(self,details=None):
details = {}
if self.authid:
details.setdefault('authid', self.authid)
details.setdefault('agent', 'swampyer-1.0')
details.setdefault('agent', self.agent)
details.setdefault('authmethods', self.authmethods or ['anonymous'])
details.setdefault('roles', {
'subscriber': {},
Expand Down
18 changes: 18 additions & 0 deletions swampyer/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import socket
import websocket
import traceback
import platform
from importlib.metadata import version

from .common import *
from .messages import *
Expand Down Expand Up @@ -76,6 +78,7 @@ class WebsocketTransport(Transport):
subprotocols = None
fire_cont_frame = False
skip_utf8_validation = False
user_agent = None

def init(self, **options):

Expand Down Expand Up @@ -104,6 +107,16 @@ def init(self, **options):
self.fire_cont_frame = options.get('fire_cont_frame',False)
self.skip_utf8_validation = options.get('skip_utf8_validation',False)

self.agent = options.get('agent')
user_agent = options.get('user_agent')
if user_agent is None:
user_agent = "Python Swampyer v{swampyer_version} / {platform}"

self.user_agent = user_agent.format(
platform = platform.platform(),
swampyer_version = version('swampyer'),
)

def connect(self, **options):
# Handle the weird issue in websocket that the origin
# port will be always http://host:port even though connection is
Expand All @@ -114,6 +127,11 @@ def connect(self, **options):
options.setdefault('sslopt',self.sslopt)
options.setdefault('subprotocols',self.subprotocols)

# Allows us to set the user agent if avaialble
header = options.setdefault('header', {})
if self.user_agent and isinstance(header, dict):
header.setdefault('user-agent', self.user_agent)

self.socket = websocket.WebSocket(
fire_cont_frame=options.pop(
"fire_cont_frame", self.fire_cont_frame),
Expand Down