Beispiel #1
0
    def testInterleaved4(self):
        """tests that http server returns responses in correct order"""
        cnn = HTTPConnection()
        cnn.connect(('localhost', SERVER_PORT))

        #we do 2 requests that should take 2 seconds to complete each.
        #if server/client pipelining was not working, fetching the 2 urls
        #would take 4 seconds on a single connection
        #if pipelining works, it should take just 2 seconds

        start = time.time()

        cnn.send(cnn.get('/sleep?3'))
        cnn.send(cnn.get('/sleep?1'))
        response1 = cnn.receive()
        response2 = cnn.receive()

        #we expect response1 to be returned first, because it was made first
        #eventhough it takes longer 
        self.assertEquals('slept 3', response1.body)
        self.assertEquals('slept 1', response2.body)       

        end = time.time()

        self.assertAlmostEqual(3, end - start, places = 1)
        
        cnn.close()
Beispiel #2
0
    def testInterleaved4(self):
        """tests that http server returns responses in correct order"""
        cnn = HTTPConnection()
        cnn.connect(('localhost', SERVER_PORT))

        #we do 2 requests that should take 2 seconds to complete each.
        #if server/client pipelining was not working, fetching the 2 urls
        #would take 4 seconds on a single connection
        #if pipelining works, it should take just 2 seconds

        start = time.time()

        cnn.send(cnn.get('/sleep?3'))
        cnn.send(cnn.get('/sleep?1'))
        response1 = cnn.receive()
        response2 = cnn.receive()

        #we expect response1 to be returned first, because it was made first
        #eventhough it takes longer
        self.assertEquals('slept 3', response1.body)
        self.assertEquals('slept 1', response2.body)

        end = time.time()

        self.assertAlmostEqual(3, end - start, places=1)

        cnn.close()
Beispiel #3
0
    def testInterleaved1(self):
        cnn = HTTPConnection()
        cnn.connect(('localhost', SERVER_PORT))

        cnn.send(cnn.get('/hello/1'))
        cnn.send(cnn.get('/hello/2'))

        response = cnn.receive()
        self.assertEquals(200, response.status_code)
        chunks = list(response)
        self.assertEquals('Hello World 1', chunks[0])

        response = cnn.receive()
        self.assertEquals(200, response.status_code)
        chunks = list(response)
        self.assertEquals('Hello World 2', chunks[0])

        cnn.close()            
Beispiel #4
0
    def testInterleaved1(self):
        cnn = HTTPConnection()
        cnn.connect(('localhost', SERVER_PORT))

        cnn.send(cnn.get('/hello/1'))
        cnn.send(cnn.get('/hello/2'))

        response = cnn.receive()
        self.assertEquals(200, response.status_code)
        chunks = list(response)
        self.assertEquals('Hello World 1', chunks[0])

        response = cnn.receive()
        self.assertEquals(200, response.status_code)
        chunks = list(response)
        self.assertEquals('Hello World 2', chunks[0])

        cnn.close()
Beispiel #5
0
    def testInterleaved3(self):
        """tests that http client and server really support pipelining"""
        cnn = HTTPConnection()
        cnn.connect(('localhost', SERVER_PORT))

        #we do 2 requests that should take 2 seconds to complete each.
        #if server/client pipelining was not working, fetching the 2 urls
        #would take 4 seconds on a single connection
        #if pipelining works, it should take just 2 seconds

        start = time.time()

        cnn.send(cnn.get('/sleep?2'))
        cnn.send(cnn.get('/sleep?2'))

        list(cnn.receive())
        list(cnn.receive())

        end = time.time()

        self.assertAlmostEqual(2, end - start, places = 1)
        
        cnn.close()
Beispiel #6
0
    def testInterleaved3(self):
        """tests that http client and server really support pipelining"""
        cnn = HTTPConnection()
        cnn.connect(('localhost', SERVER_PORT))

        #we do 2 requests that should take 2 seconds to complete each.
        #if server/client pipelining was not working, fetching the 2 urls
        #would take 4 seconds on a single connection
        #if pipelining works, it should take just 2 seconds

        start = time.time()

        cnn.send(cnn.get('/sleep?2'))
        cnn.send(cnn.get('/sleep?2'))

        list(cnn.receive())
        list(cnn.receive())

        end = time.time()

        self.assertAlmostEqual(2, end - start, places=1)

        cnn.close()
def main():
    
    cnn = HTTPConnection()
    cnn.connect(('www.google.com', 80))

    request = cnn.get('/')

    #you can send multiple http requests on the same connection:
    cnn.send(request) #request 1
    cnn.send(request) #request 2

    #and receive the corresponding responses    
    response1 = cnn.receive()
    response2 = cnn.receive()

    print response1.status
    print response1.headers
    print response1.body

    print response2.status
    print response2.headers
    print response2.body

    cnn.close()
Beispiel #8
0
def main():

    cnn = HTTPConnection()
    cnn.connect(('www.google.com', 80))

    request = cnn.get('/')

    #you can send multiple http requests on the same connection:
    cnn.send(request)  #request 1
    cnn.send(request)  #request 2

    #and receive the corresponding responses
    response1 = cnn.receive()
    response2 = cnn.receive()

    print response1.status
    print response1.headers
    print response1.body

    print response2.status
    print response2.headers
    print response2.body

    cnn.close()