print('Using %s as output directory' % (out_dir))
 print('Trying to connect to %s:%i' % (host, port))
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.connect((host, port))
 connection = TLSConnection(sock)
 connection.handshakeClientCert(nextProtos=["spdy/%i" % SPDY_VERSION])
 print ('TLS NPN Selected: %s' % connection.next_proto)
 spdy_ctx = Context(CLIENT, version=SPDY_VERSION)
 connection.write(get_site_resource(spdy_ctx, host))
 headers = {spdy_ctx._last_stream_id: {'path': 'index'}}
 res_files = {spdy_ctx._last_stream_id: (os.path.join(out_dir, 'index'), None)}
 resources = None
 goaway = False
 while not goaway:
     answer = connection.read() # Blocking
     spdy_ctx.incoming(answer)
     frame = get_frame(spdy_ctx)
     while frame:
         sid = getattr(frame, 'stream_id', None)
         if hasattr(frame, 'headers'):
             print ('<<', frame, 'Headers:', frame.headers) # DEBUG
             if sid not in headers:
                 headers[sid] = {}
             headers[sid].update(parse_headers(frame.headers))
         elif hasattr(frame, 'data'):
             data = frame.data
             if headers[sid].get(':status', '').startswith('200'): # OK
                 res_path, res_fd = res_files[sid]
                 if res_fd is None: # File not opened yet
                     if not os.path.exists(os.path.dirname(res_path)):
                         os.makedirs(os.path.dirname(res_path))
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.connect((host, port))
 connection = TLSConnection(sock)
 connection.handshakeClientCert(nextProtos=["spdy/%i" % SPDY_VERSION])
 print('TLS NPN Selected: %s' % connection.next_proto)
 spdy_ctx = Context(CLIENT, version=SPDY_VERSION)
 connection.write(get_site_resource(spdy_ctx, host))
 headers = {spdy_ctx._last_stream_id: {'path': 'index'}}
 res_files = {
     spdy_ctx._last_stream_id: (os.path.join(out_dir, 'index'), None)
 }
 resources = None
 goaway = False
 while not goaway:
     answer = connection.read()  # Blocking
     spdy_ctx.incoming(answer)
     frame = get_frame(spdy_ctx)
     while frame:
         sid = getattr(frame, 'stream_id', None)
         if hasattr(frame, 'headers'):
             print('<<', frame, 'Headers:', frame.headers)  # DEBUG
             if sid not in headers:
                 headers[sid] = {}
             headers[sid].update(parse_headers(frame.headers))
         elif hasattr(frame, 'data'):
             data = frame.data
             if headers[sid].get(':status', '').startswith('200'):  # OK
                 res_path, res_fd = res_files[sid]
                 if res_fd is None:  # File not opened yet
                     if not os.path.exists(os.path.dirname(res_path)):
                         os.makedirs(os.path.dirname(res_path))
Beispiel #3
0
#!/usr/bin/env python
# coding: utf-8

from spdy.context import Context, CLIENT, SERVER
from spdy.frames import SynStream, SynReply

server = Context(SERVER)
client = Context(CLIENT)

frame = SynStream(stream_id=client.next_stream_id, headers={'dood': 'balls', 'stuff': 'otherstuff'})
client.put_frame(frame)
chunk = client.outgoing()

server.incoming(chunk)
frame2 = server.get_frame()
print(frame2)
print(frame2.headers)

frame3 = SynReply(stream_id=server.next_stream_id, headers={'got it': 'yup', 'roger': 'roger'})
server.put_frame(frame3)
chunk2 = server.outgoing()

client.incoming(chunk2)
frame4 = client.get_frame()
print(frame4.headers)
Beispiel #4
0
        data = DataFrame(f.stream_id, b"hello, world!", flags=1)
        conn.put_frame(data)
        print(str(data) + ", SAYS SERVER")
        goaway = Goaway(f.stream_id)
        conn.put_frame(goaway)
        print(str(goaway) + ", SAYS SERVER")
    elif isinstance(f, Goaway):
        return True

try:
    print ('Running one-time one-client SPDY Server...')
    client_socket, address = server.accept()
    ss = ctx.wrap_socket(client_socket, server_side=True)
    conn = Context(SERVER)
    finish = False
    while not finish:
        d = ss.recv(1024)
        conn.incoming(d)
        frame = conn.get_frame()
        if frame:
            finish = handle_frame(conn, frame)
            outgoing = conn.outgoing()
            if outgoing:
                ss.sendall(outgoing)
        

except Exception as exc:
    print(exc)
finally:
    server.close()
        data = DataFrame(f.stream_id, b"hello, world!", flags=1)
        conn.put_frame(data)
        print(str(data) + ", SAYS SERVER")
        goaway = Goaway(f.stream_id)
        conn.put_frame(goaway)
        print(str(goaway) + ", SAYS SERVER")
    elif isinstance(f, Goaway):
        return True


try:
    print('Running one-time one-client SPDY Server...')
    client_socket, address = server.accept()
    ss = ctx.wrap_socket(client_socket, server_side=True)
    conn = Context(SERVER)
    finish = False
    while not finish:
        d = ss.recv(1024)
        conn.incoming(d)
        frame = conn.get_frame()
        if frame:
            finish = handle_frame(conn, frame)
            outgoing = conn.outgoing()
            if outgoing:
                ss.sendall(outgoing)

except Exception as exc:
    print(exc)
finally:
    server.close()