-
-
Save wallrj/9174fb2b76e351a1e939 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
(Twisted)[richard@zorin redux-4888]$ python docs/web/examples/https.py https://buildbot.twistedmatrix.com/json/builders/?as_text=1 | |
... | |
], | |
"category": "supported", | |
"schedulers": [ | |
"all", | |
"force-supported" | |
], | |
"slaves": [ | |
"tomprince-socrates-winxp-1" | |
], | |
"state": "idle" | |
} | |
} | |
""" | |
from __future__ import print_function | |
import sys | |
from twisted.internet.task import react | |
from twisted.web.client import Agent, readBody, WebClientConnectionCreatorCreator | |
class HostnameOverrideWebClientConnectionCreatorCreator(WebClientConnectionCreatorCreator): | |
def __init__(self, *args, **kwargs): | |
self._expectedHostname = kwargs.pop('expectedHostname') | |
WebClientConnectionCreatorCreator.__init__(self, *args, **kwargs) | |
def creatorForNetloc(self, hostname, port): | |
return WebClientConnectionCreatorCreator.creatorForNetloc(self, self._expectedHostname, port) | |
def main(reactor): | |
cf = HostnameOverrideWebClientConnectionCreatorCreator(expectedHostname=u'www.twistedmatrix.com') | |
c = Agent(reactor=reactor, contextFactory=cf) | |
d = c.request('GET', sys.argv[1]) | |
d.addCallback(readBody) | |
d.addCallback(print) | |
return d | |
react(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment