2012-08-22 20:15:35 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# The example SPDY client. You need Python 3.3 or later because we
|
|
|
|
# use TLS NPN.
|
|
|
|
#
|
2012-08-27 18:47:21 +02:00
|
|
|
# Usage: spdyclient.py URL...
|
2012-08-22 20:15:35 +02:00
|
|
|
#
|
|
|
|
import sys
|
|
|
|
import spdylay
|
|
|
|
|
2012-08-27 18:47:21 +02:00
|
|
|
class MyStreamHandler(spdylay.BaseSPDYStreamHandler):
|
|
|
|
def on_header(self, nv):
|
|
|
|
sys.stdout.write('Stream#{}\n'.format(self.stream_id))
|
|
|
|
for k, v in nv:
|
|
|
|
sys.stdout.write('{}: {}\n'.format(k, v))
|
2012-08-22 20:15:35 +02:00
|
|
|
|
2012-08-27 18:47:21 +02:00
|
|
|
def on_data(self, data):
|
|
|
|
sys.stdout.write('Stream#{}\n'.format(self.stream_id))
|
|
|
|
sys.stdout.buffer.write(data)
|
2012-08-22 20:15:35 +02:00
|
|
|
|
2012-08-27 18:47:21 +02:00
|
|
|
def on_close(self, status_code):
|
|
|
|
sys.stdout.write('Stream#{} closed\n'.format(self.stream_id))
|
2012-08-22 20:15:35 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-08-27 18:47:21 +02:00
|
|
|
uris = sys.argv[1:]
|
|
|
|
spdylay.urlfetch(uris, MyStreamHandler)
|