autobahn-python
autobahn-python copied to clipboard
proxy port is ignored by asyncio ApplicationRunner
Steps to Reproduce
- Use asyncio
- Use the old ApplicationRunner API
- Pass the
proxy
kwarg with host and port where port != 443 - Invoke sample code thusly:
sample.py wss://myrouter.com/ws realm1 myproxy.com:3128
Expected Result
autobahn connects successfully
Actual Result
dropping connection to peer tcp4:10.1.6.95:443 with abort=True: None
(notice I specified port 3128)
Sample Code
import sys
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
import txaio
txaio.start_logging( level = 'debug' )
class Application( ApplicationSession ):
def onJoin( self, details ):
print( 'joined session' )
proxy_host, proxy_port = sys.argv[3].split( ':' )
runner = ApplicationRunner(
sys.argv[1],
sys.argv[2],
proxy = dict(
host = proxy_host,
port = int( proxy_port )
),
)
runner.run( Application )
Notes
2019-09-27T14:59:27
[('logOctets', False, 'WampWebSocketClientFactory'),
('logFrames', False, 'WampWebSocketClientFactory'),
('trackTimings', False, 'WampWebSocketClientFactory'),
('utf8validateIncoming', True, 'WampWebSocketClientFactory'),
('applyMask', True, 'WampWebSocketClientFactory'),
('maxFramePayloadSize', 1048576, 'WampWebSocketClientFactory'),
('maxMessagePayloadSize', 1048576, 'WampWebSocketClientFactory'),
('autoFragmentSize', 65536, 'WampWebSocketClientFactory'),
('failByDrop', False, 'WampWebSocketClientFactory'),
('echoCloseCodeReason', False, 'WampWebSocketClientFactory'),
('openHandshakeTimeout', 2.5, 'WampWebSocketClientFactory'),
('closeHandshakeTimeout', 1, 'WampWebSocketClientFactory'),
('tcpNoDelay', True, 'WampWebSocketClientFactory'),
('autoPingInterval', 10.0, 'WampWebSocketClientFactory'),
('autoPingTimeout', 5.0, 'WampWebSocketClientFactory'),
('autoPingSize', 4, 'WampWebSocketClientFactory'),
('version', 18, 'WampWebSocketClientFactory'),
('acceptMaskedServerFrames', False, 'WampWebSocketClientFactory'),
('maskClientFrames', True, 'WampWebSocketClientFactory'),
('serverConnectionDropTimeout', 1, 'WampWebSocketClientFactory'),
('perMessageCompressionOffers',
[PerMessageDeflateOffer(accept_no_context_takeover = True, accept_max_window_bits = True, request_no_context_takeover = False, request_max_window_bits = 0)],
'WampWebSocketClientFactory'),
('perMessageCompressionAccept',
<function ApplicationRunner.run.<locals>.accept at 0x7f53e8d8ab70>,
'WampWebSocketClientFactory')]
2019-09-27T14:59:27 connection to tcp4:10.1.6.95:443 established
2019-09-27T14:59:27 CONNECT redacted.company.com:443 HTTP/1.1
Host: redacted.company.com:443
2019-09-27T14:59:27 received HTTP response:
b'HTTP/1.1 400 Bad Request\r\nServer: nginx\r\nDate: Fri, 27 Sep 2019 18:59:27 GMT\r\nContent-Type: text/html\r\nContent-Length: 150\r\nConnection: close\r\nX-Frame-Options: SAMEORIGIN\r\nX-X
SS-Protection: 1; mode=block\r\n\r\n'
2019-09-27T14:59:27 received HTTP status line for proxy connect request : HTTP/1.1 400 Bad Request
2019-09-27T14:59:27 received HTTP headers for proxy connect request : {'server': 'nginx', 'date': 'Fri, 27 Sep 2019 18:59:27 GMT', 'content-type': 'text/html', 'content-length': '150', 'conne
ction': 'close', 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '1; mode=block'}
2019-09-27T14:59:27 failing proxy connect ('HTTP proxy connect failed (400 - BadRequest)')
2019-09-27T14:59:27 dropping connection to peer tcp4:10.1.6.95:443 with abort=True: None
2019-09-27T14:59:27 _connectionLost: None
Notice the line
2019-09-27T14:59:27 connection to tcp4:10.1.6.95:443 established
It's taking my host option, but assuming port 443 even though I said port 3128. Something else on that box (nginx) is listening on 443 and responds with http 400 because it isn't a proxy.
Note that this works in twisted. Change the import to autobahn.twisted.wamp
and you'll get the Expected Result.