Permalink
Browse files

added SSL support

  • Loading branch information...
1 parent 15fbb3b commit 16029ceafb3fe521a8aa762dc0e52299ecd0c012 @guyzmo committed Jul 2, 2012
Showing with 36 additions and 3 deletions.
  1. +13 −3 eventsource/client.py
  2. +23 −0 eventsource/listener.py
View
@@ -31,7 +31,7 @@ class EventSourceClient(object):
"""
This module opens a new connection to an eventsource server, and wait for events.
"""
- def __init__(self,url,action,target,callback=None,retry=0):
+ def __init__(self,url,action,target,callback=None,retry=0,ssl=False):
"""
Build the event source client
:param url: string, the url to connect to
@@ -42,7 +42,10 @@ def __init__(self,url,action,target,callback=None,retry=0):
"""
log.debug("EventSourceClient(%s,%s,%s,%s,%s)" % (url,action,target,callback,retry))
- self._url = "http://%s/%s/%s" % (url,action,target)
+ if ssl:
+ self._url = "https://%s/%s/%s" % (url,action,target)
+ else:
+ self._url = "http://%s/%s/%s" % (url,action,target)
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
self.http_client = AsyncHTTPClient()
self.http_request = HTTPRequest(url=self._url,
@@ -147,6 +150,12 @@ def start():
default='8888',
help='Port to be used connection')
+ parser.add_argument("-S",
+ "--ssl",
+ dest="ssl",
+ action="store_true",
+ help='enables HTTPS scheme support')
+
parser.add_argument("-d",
"--debug",
dest="debug",
@@ -177,7 +186,8 @@ def log_events(event):
EventSourceClient(url="%(host)s:%(port)s" % args.__dict__,
action="poll",
target=args.token,
- retry=args.retry).poll()
+ retry=args.retry,
+ ssl=args.ssl).poll()
###
View
@@ -13,6 +13,7 @@
- http://github.com/guyzmo/event-source-library/
"""
+import os
import sys
import time
import argparse
@@ -22,6 +23,7 @@
import json
import httplib
import tornado.web
+import tornado.httpserver
import tornado.ioloop
"""Event base"""
@@ -376,6 +378,18 @@ def start():
default='8888',
help='Port to bind on')
+ parser.add_argument("-K",
+ "--keyfile",
+ dest="ssl_keyfile",
+ default='',
+ help='Path to Key file\nif specified with --certfile, SSL is enabled')
+
+ parser.add_argument("-C",
+ "--certfile",
+ dest="ssl_certfile",
+ default='',
+ help='Path to CA Cert file\nif specified with --keyfile, SSL is enabled')
+
parser.add_argument("-d",
"--debug",
dest="debug",
@@ -430,6 +444,15 @@ def start():
(r"/(.*)/(.*)", EventSourceHandler, dict(event_class=chosen_event,keepalive=args.keepalive)),
])
+ if args.ssl_certfile != '' or args.ssl_keyfile != '':
+ if os.path.exists(args.ssl_certfile) and os.path.exists(args.ssl_keyfile):
+ application = tornado.httpserver.HTTPServer(application, ssl_options={
+ "certfile": args.ssl_certfile,
+ "keyfile": args.ssl_keyfile,
+ })
+ else:
+ log.error("[-C|--certfile] and [-K|--keyfile] shall be specified *together* to enable SSL use. SSL is disabled.")
+
application.listen(int(args.port))
tornado.ioloop.IOLoop.instance().start()
except ValueError:

0 comments on commit 16029ce

Please sign in to comment.