~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/web2/test/simple_client.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import socket, sys
 
2
 
 
3
test_type = sys.argv[1]
 
4
port = int(sys.argv[2])
 
5
socket_type = sys.argv[3]
 
6
 
 
7
s = socket.socket(socket.AF_INET)
 
8
s.connect(("127.0.0.1", port))
 
9
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 40000)
 
10
 
 
11
if socket_type == 'ssl':
 
12
    s2 = socket.ssl(s)
 
13
    send=s2.write
 
14
    recv=s2.read
 
15
else:
 
16
    send=s.send
 
17
    recv=s.recv
 
18
    
 
19
print >> sys.stderr, ">> Making %s request to port %d" % (socket_type, port)
 
20
 
 
21
send("GET /error HTTP/1.0\r\n")
 
22
send("Host: localhost\r\n")
 
23
 
 
24
if test_type == "lingeringClose":
 
25
    print >> sys.stderr, ">> Sending lots of data"
 
26
    send("Content-Length: 1000000\r\n\r\n")
 
27
    send("X"*1000000)
 
28
else:
 
29
    send('\r\n')
 
30
 
 
31
#import time
 
32
#time.sleep(5)
 
33
print >> sys.stderr, ">> Getting data"
 
34
data=''
 
35
while len(data) < 299999:
 
36
    try:
 
37
        x=recv(10000)
 
38
    except:
 
39
        break
 
40
    if x == '':
 
41
        break
 
42
    data+=x
 
43
sys.stdout.write(data)