Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'dinsic/rav/proxy-support-base' into rav…
Browse files Browse the repository at this point in the history
…/proxy-support
  • Loading branch information
richvdh committed Oct 23, 2019
2 parents 2bbaada + fe4ab0d commit 5ecc002
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
24 changes: 15 additions & 9 deletions synapse/http/connectproxyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class HTTPProxiedClientFactory(protocol.ClientFactory):
HTTP Protocol object and run the rest of the connection.
Args:
dst_host (bytes): The original HTTP(s) hostname or IPv4 or IPv6 address literal.
dst_port (int): The original HTTP(s) port
dst_host (bytes): hostname that we want to CONNECT to
dst_port (int): port that we want to connect to
wrapped_factory (protocol.ClientFactory): The original Factory
"""

Expand Down Expand Up @@ -109,12 +109,19 @@ def clientConnectionLost(self, connector, reason):


class HTTPConnectProtocol(protocol.Protocol):
"""Protocol that wraps http factory with CONNECT proxy handshake on connect
"""Protocol that wraps an existing Protocol to do a CONNECT handshake at connect
Args:
host (bytes): The original HTTP(s) hostname or IPv4 or IPv6 address literal.
host (bytes): The original HTTP(s) hostname or IPv4 or IPv6 address literal
to put in the CONNECT request
port (int): The original HTTP(s) port
port (int): The original HTTP(s) port to put in the CONNECT request
wrapped_protocol (interfaces.IProtocol): the original protocol (probably
HTTPChannel or TLSMemoryBIOProtocol, but could be anything really)
connected_deferred (Deferred): a Deferred which will be callbacked with
wrapped_protocol when the CONNECT completes
"""

def __init__(self, host, port, wrapped_protocol, connected_deferred):
Expand Down Expand Up @@ -142,7 +149,7 @@ def proxyConnected(self, _):

self.connected_deferred.callback(self.wrapped_protocol)

# Get any pending data from the http buf and forward it to the http protocol
# Get any pending data from the http buf and forward it to the original protocol
buf = self.http_setup_client.clearLineBuffer()
if buf:
self.wrapped_protocol.dataReceived(buf)
Expand All @@ -161,9 +168,8 @@ class HTTPConnectSetupClient(http.HTTPClient):
"""HTTPClient protocol to send a CONNECT message for proxies and read the response.
Args:
host (bytes): The original HTTP(s) hostname or IPv4 or IPv6 address literal.
port (int): The original HTTP(s) port
host (bytes): The hostname to send in the CONNECT message
port (int): The port to send in the CONNECT message
"""

def __init__(self, host, port):
Expand Down
4 changes: 2 additions & 2 deletions tests/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from OpenSSL.SSL import Connection
from twisted.internet.interfaces import IOpenSSLServerConnectionCreator
from twisted.internet.ssl import Certificate, trustRootFromCertificates
from twisted.web.client import BrowserLikePolicyForHTTPS
from twisted.web.iweb import IPolicyForHTTPS
from twisted.web.client import BrowserLikePolicyForHTTPS # noqa: F401
from twisted.web.iweb import IPolicyForHTTPS # noqa: F401


def get_test_https_policy():
Expand Down
4 changes: 1 addition & 3 deletions tests/http/test_proxyagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

import treq

from twisted.internet import interfaces
from twisted.internet import interfaces # noqa: F401
from twisted.internet.protocol import Factory
from twisted.protocols.tls import TLSMemoryBIOFactory
from twisted.web.http import HTTPChannel

from synapse.http.proxyagent import ProxyAgent

from tests import unittest
from tests.http import TestServerTLSConnectionFactory, get_test_https_policy
from tests.server import FakeTransport, ThreadedMemoryReactorClock
from tests.unittest import TestCase
Expand All @@ -33,7 +32,6 @@
HTTPFactory = Factory.forProtocol(HTTPChannel)


@unittest.DEBUG
class MatrixFederationAgentTests(TestCase):
def setUp(self):
self.reactor = ThreadedMemoryReactorClock()
Expand Down
2 changes: 1 addition & 1 deletion tests/push/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def post_json_get_json(url, body):
config = self.default_config()
config["start_pushers"] = True

hs = self.setup_test_homeserver(config=config, simple_http_client=m)
hs = self.setup_test_homeserver(config=config, proxied_http_client=m)

return hs

Expand Down

0 comments on commit 5ecc002

Please sign in to comment.