Skip to content

Instantly share code, notes, and snippets.

@wallrj

wallrj/https.py Secret

Created April 20, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallrj/9174fb2b76e351a1e939 to your computer and use it in GitHub Desktop.
Save wallrj/9174fb2b76e351a1e939 to your computer and use it in GitHub Desktop.
"""
(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