Ejemplo n.º 1
0
 def test_keepalive_http11_connclose(self):
     # specifying Connection: close explicitly
     data = "Don't keep me alive"
     s = tobytes("GET / HTTP/1.1\n"
                 "Connection: close\n"
                 "Content-Length: %d\n"
                 "\n"
                 "%s" % (len(data), data))
     self.sock.connect((self.host, self.port))
     self.sock.send(s)
     response = httplib.HTTPResponse(self.sock)
     response.begin()
     self.assertEqual(int(response.status), 200)
     self.assertEqual(response.getheader('connection'), 'close')
Ejemplo n.º 2
0
 def test_keepalive_http11_explicit(self):
     # Explicitly set keep-alive
     data = "Default: Keep me alive"
     s = tobytes("GET / HTTP/1.1\n"
                 "Connection: keep-alive\n"
                 "Content-Length: %d\n"
                 "\n"
                 "%s" % (len(data), data))
     self.sock.connect((self.host, self.port))
     self.sock.send(s)
     response = httplib.HTTPResponse(self.sock)
     response.begin()
     self.assertEqual(int(response.status), 200)
     self.assertTrue(response.getheader('connection') != 'close')
Ejemplo n.º 3
0
    def test_keepalive_http_11(self):
        # Handling of Keep-Alive within HTTP 1.1

        # All connections are kept alive, unless stated otherwise
        data = "Default: Keep me alive"
        s = tobytes("GET / HTTP/1.1\n"
                    "Content-Length: %d\n"
                    "\n"
                    "%s" % (len(data), data))
        self.sock.connect((self.host, self.port))
        self.sock.send(s)
        response = httplib.HTTPResponse(self.sock)
        response.begin()
        self.assertEqual(int(response.status), 200)
        self.assertTrue(response.getheader('connection') != 'close')
Ejemplo n.º 4
0
 def test_keepalive_http_10(self):
     # Handling of Keep-Alive within HTTP 1.0
     data = "Default: Don't keep me alive"
     s = tobytes("GET / HTTP/1.0\n"
                 "Content-Length: %d\n"
                 "\n"
                 "%s" % (len(data), data))
     self.sock.connect((self.host, self.port))
     self.sock.send(s)
     response = httplib.HTTPResponse(self.sock)
     response.begin()
     self.assertEqual(int(response.status), 200)
     connection = response.getheader('Connection', '')
     # We sent no Connection: Keep-Alive header
     # Connection: close (or no header) is default.
     self.assertTrue(connection != 'Keep-Alive')
Ejemplo n.º 5
0
 def test_keepalive_http10_explicit(self):
     # If header Connection: Keep-Alive is explicitly sent,
     # we want to keept the connection open, we also need to return
     # the corresponding header
     data = "Keep me alive"
     s = tobytes("GET / HTTP/1.0\n"
                 "Connection: Keep-Alive\n"
                 "Content-Length: %d\n"
                 "\n"
                 "%s" % (len(data), data))
     self.sock.connect((self.host, self.port))
     self.sock.send(s)
     response = httplib.HTTPResponse(self.sock)
     response.begin()
     self.assertEqual(int(response.status), 200)
     connection = response.getheader('Connection', '')
     self.assertEqual(connection, 'Keep-Alive')