예제 #1
0
 def test_Chunked_Encoding(self):
     if cherrypy.server.protocol_version != 'HTTP/1.1':
         return self.skip()
     if hasattr(self, 'harness') and 'modpython' in self.harness.__class__.__name__.lower():
         return self.skip()
     self.PROTOCOL = 'HTTP/1.1'
     self.persistent = True
     conn = self.HTTP_CONN
     body = ntob('8;key=value\r\nxx\r\nxxxx\r\n5\r\nyyyyy\r\n0\r\nContent-Type: application/json\r\n\r\n')
     conn.putrequest('POST', '/upload', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.putheader('Transfer-Encoding', 'chunked')
     conn.putheader('Trailer', 'Content-Type')
     conn.putheader('Content-Length', '3')
     conn.endheaders()
     conn.send(body)
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus('200 OK')
     self.assertBody("thanks for '%s'" % ntob('xx\r\nxxxxyyyyy'))
     body = ntob('3e3\r\n' + 'x' * 995 + '\r\n0\r\n\r\n')
     conn.putrequest('POST', '/upload', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.putheader('Transfer-Encoding', 'chunked')
     conn.putheader('Content-Type', 'text/plain')
     conn.endheaders()
     conn.send(body)
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(413)
     conn.close()
예제 #2
0
 def test_Chunked_Encoding(self):
     if cherrypy.server.protocol_version != 'HTTP/1.1':
         return self.skip()
     if hasattr(
             self, 'harness'
     ) and 'modpython' in self.harness.__class__.__name__.lower():
         return self.skip()
     self.PROTOCOL = 'HTTP/1.1'
     self.persistent = True
     conn = self.HTTP_CONN
     body = ntob(
         '8;key=value\r\nxx\r\nxxxx\r\n5\r\nyyyyy\r\n0\r\nContent-Type: application/json\r\n\r\n'
     )
     conn.putrequest('POST', '/upload', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.putheader('Transfer-Encoding', 'chunked')
     conn.putheader('Trailer', 'Content-Type')
     conn.putheader('Content-Length', '3')
     conn.endheaders()
     conn.send(body)
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus('200 OK')
     self.assertBody("thanks for '%s'" % ntob('xx\r\nxxxxyyyyy'))
     body = ntob('3e3\r\n' + 'x' * 995 + '\r\n0\r\n\r\n')
     conn.putrequest('POST', '/upload', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.putheader('Transfer-Encoding', 'chunked')
     conn.putheader('Content-Type', 'text/plain')
     conn.endheaders()
     conn.send(body)
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(413)
     conn.close()
예제 #3
0
    def test_readall_or_close(self):
        if cherrypy.server.protocol_version != 'HTTP/1.1':
            return self.skip()
        self.PROTOCOL = 'HTTP/1.1'
        if self.scheme == 'https':
            self.HTTP_CONN = HTTPSConnection
        else:
            self.HTTP_CONN = HTTPConnection
        old_max = cherrypy.server.max_request_body_size
        for new_max in (0, old_max):
            cherrypy.server.max_request_body_size = new_max
            self.persistent = True
            conn = self.HTTP_CONN
            conn.putrequest('POST', '/err_before_read', skip_host=True)
            conn.putheader('Host', self.HOST)
            conn.putheader('Content-Type', 'text/plain')
            conn.putheader('Content-Length', '1000')
            conn.putheader('Expect', '100-continue')
            conn.endheaders()
            response = conn.response_class(conn.sock, method='POST')
            version, status, reason = response._read_status()
            self.assertEqual(status, 100)
            while True:
                skip = response.fp.readline().strip()
                if not skip:
                    break

            conn.send(ntob('x' * 1000))
            response.begin()
            self.status, self.headers, self.body = webtest.shb(response)
            self.assertStatus(500)
            conn._output(ntob('POST /upload HTTP/1.1'))
            conn._output(ntob('Host: %s' % self.HOST, 'ascii'))
            conn._output(ntob('Content-Type: text/plain'))
            conn._output(ntob('Content-Length: 17'))
            conn._output(ntob('Expect: 100-continue'))
            conn._send_output()
            response = conn.response_class(conn.sock, method='POST')
            version, status, reason = response._read_status()
            self.assertEqual(status, 100)
            while True:
                skip = response.fp.readline().strip()
                if not skip:
                    break

            body = ntob('I am a small file')
            conn.send(body)
            response.begin()
            self.status, self.headers, self.body = webtest.shb(response)
            self.assertStatus(200)
            self.assertBody("thanks for '%s'" % body)
            conn.close()
예제 #4
0
    def test_readall_or_close(self):
        if cherrypy.server.protocol_version != 'HTTP/1.1':
            return self.skip()
        self.PROTOCOL = 'HTTP/1.1'
        if self.scheme == 'https':
            self.HTTP_CONN = HTTPSConnection
        else:
            self.HTTP_CONN = HTTPConnection
        old_max = cherrypy.server.max_request_body_size
        for new_max in (0, old_max):
            cherrypy.server.max_request_body_size = new_max
            self.persistent = True
            conn = self.HTTP_CONN
            conn.putrequest('POST', '/err_before_read', skip_host=True)
            conn.putheader('Host', self.HOST)
            conn.putheader('Content-Type', 'text/plain')
            conn.putheader('Content-Length', '1000')
            conn.putheader('Expect', '100-continue')
            conn.endheaders()
            response = conn.response_class(conn.sock, method='POST')
            version, status, reason = response._read_status()
            self.assertEqual(status, 100)
            while True:
                skip = response.fp.readline().strip()
                if not skip:
                    break

            conn.send(ntob('x' * 1000))
            response.begin()
            self.status, self.headers, self.body = webtest.shb(response)
            self.assertStatus(500)
            conn._output(ntob('POST /upload HTTP/1.1'))
            conn._output(ntob('Host: %s' % self.HOST, 'ascii'))
            conn._output(ntob('Content-Type: text/plain'))
            conn._output(ntob('Content-Length: 17'))
            conn._output(ntob('Expect: 100-continue'))
            conn._send_output()
            response = conn.response_class(conn.sock, method='POST')
            version, status, reason = response._read_status()
            self.assertEqual(status, 100)
            while True:
                skip = response.fp.readline().strip()
                if not skip:
                    break

            body = ntob('I am a small file')
            conn.send(body)
            response.begin()
            self.status, self.headers, self.body = webtest.shb(response)
            self.assertStatus(200)
            self.assertBody("thanks for '%s'" % body)
            conn.close()
예제 #5
0
파일: test_conn.py 프로젝트: cread/ec2id
    def test_Chunked_Encoding(self):
        if cherrypy.server.protocol_version != "HTTP/1.1":
            print "skipped ",
            return
        
        if (hasattr(self, 'harness') and
            "modpython" in self.harness.__class__.__name__.lower()):
            # mod_python forbids chunked encoding
            print "skipped ",
            return
        
        self.PROTOCOL = "HTTP/1.1"
        
        # Set our HTTP_CONN to an instance so it persists between requests.
        self.persistent = True
        conn = self.HTTP_CONN
        
        # Try a normal chunked request (with extensions)
        body = ("8;key=value\r\nxx\r\nxxxx\r\n5\r\nyyyyy\r\n0\r\n"
                "Content-Type: application/x-json\r\n\r\n")
        conn.putrequest("POST", "/upload", skip_host=True)
        conn.putheader("Host", self.HOST)
        conn.putheader("Transfer-Encoding", "chunked")
        conn.putheader("Trailer", "Content-Type")
        # Note that this is somewhat malformed:
        # we shouldn't be sending Content-Length.
        # RFC 2616 says the server should ignore it.
        conn.putheader("Content-Length", len(body))
        conn.endheaders()
        conn.send(body)
        response = conn.getresponse()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus('200 OK')
        self.assertBody("thanks for 'xx\r\nxxxxyyyyy' (application/x-json)")
        
        # Try a chunked request that exceeds server.max_request_body_size.
        # Note that the delimiters and trailer are included.
        body = "3e3\r\n" + ("x" * 995) + "\r\n0\r\n\r\n"
        conn.putrequest("POST", "/upload", skip_host=True)
        conn.putheader("Host", self.HOST)
        conn.putheader("Transfer-Encoding", "chunked")
        conn.putheader("Content-Type", "text/plain")
        # Chunked requests don't need a content-length
##        conn.putheader("Content-Length", len(body))
        conn.endheaders()
        conn.send(body)
        response = conn.getresponse()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus(413)
        self.assertBody("")
        conn.close()
예제 #6
0
    def test_Chunked_Encoding(self):
        if cherrypy.server.protocol_version != "HTTP/1.1":
            print "skipped ",
            return

        if (hasattr(self, 'harness')
                and "modpython" in self.harness.__class__.__name__.lower()):
            # mod_python forbids chunked encoding
            print "skipped ",
            return

        self.PROTOCOL = "HTTP/1.1"

        # Set our HTTP_CONN to an instance so it persists between requests.
        self.persistent = True
        conn = self.HTTP_CONN

        # Try a normal chunked request (with extensions)
        body = ("8;key=value\r\nxx\r\nxxxx\r\n5\r\nyyyyy\r\n0\r\n"
                "Content-Type: application/x-json\r\n\r\n")
        conn.putrequest("POST", "/upload", skip_host=True)
        conn.putheader("Host", self.HOST)
        conn.putheader("Transfer-Encoding", "chunked")
        conn.putheader("Trailer", "Content-Type")
        # Note that this is somewhat malformed:
        # we shouldn't be sending Content-Length.
        # RFC 2616 says the server should ignore it.
        conn.putheader("Content-Length", len(body))
        conn.endheaders()
        conn.send(body)
        response = conn.getresponse()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus('200 OK')
        self.assertBody("thanks for 'xx\r\nxxxxyyyyy' (application/x-json)")

        # Try a chunked request that exceeds server.max_request_body_size.
        # Note that the delimiters and trailer are included.
        body = "3e3\r\n" + ("x" * 995) + "\r\n0\r\n\r\n"
        conn.putrequest("POST", "/upload", skip_host=True)
        conn.putheader("Host", self.HOST)
        conn.putheader("Transfer-Encoding", "chunked")
        conn.putheader("Content-Type", "text/plain")
        # Chunked requests don't need a content-length
        ##        conn.putheader("Content-Length", len(body))
        conn.endheaders()
        conn.send(body)
        response = conn.getresponse()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus(413)
        self.assertBody("")
        conn.close()
예제 #7
0
    def test_Chunked_Encoding(self):
        if cherrypy.server.protocol_version != 'HTTP/1.1':
            return self.skip()

        if (hasattr(self, 'harness') and
                'modpython' in self.harness.__class__.__name__.lower()):
            # mod_python forbids chunked encoding
            return self.skip()

        self.PROTOCOL = 'HTTP/1.1'

        # Set our HTTP_CONN to an instance so it persists between requests.
        self.persistent = True
        conn = self.HTTP_CONN

        # Try a normal chunked request (with extensions)
        body = ntob('8;key=value\r\nxx\r\nxxxx\r\n5\r\nyyyyy\r\n0\r\n'
                    'Content-Type: application/json\r\n'
                    '\r\n')
        conn.putrequest('POST', '/upload', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.putheader('Transfer-Encoding', 'chunked')
        conn.putheader('Trailer', 'Content-Type')
        # Note that this is somewhat malformed:
        # we shouldn't be sending Content-Length.
        # RFC 2616 says the server should ignore it.
        conn.putheader('Content-Length', '3')
        conn.endheaders()
        conn.send(body)
        response = conn.getresponse()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus('200 OK')
        self.assertBody("thanks for '%s'" % ntob('xx\r\nxxxxyyyyy'))

        # Try a chunked request that exceeds server.max_request_body_size.
        # Note that the delimiters and trailer are included.
        body = ntob('3e3\r\n' + ('x' * 995) + '\r\n0\r\n\r\n')
        conn.putrequest('POST', '/upload', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.putheader('Transfer-Encoding', 'chunked')
        conn.putheader('Content-Type', 'text/plain')
        # Chunked requests don't need a content-length
        ##        conn.putheader("Content-Length", len(body))
        conn.endheaders()
        conn.send(body)
        response = conn.getresponse()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus(413)
        conn.close()
    def test_Chunked_Encoding(self):
        if cherrypy.server.protocol_version != 'HTTP/1.1':
            return self.skip()

        if (hasattr(self, 'harness')
                and 'modpython' in self.harness.__class__.__name__.lower()):
            # mod_python forbids chunked encoding
            return self.skip()

        self.PROTOCOL = 'HTTP/1.1'

        # Set our HTTP_CONN to an instance so it persists between requests.
        self.persistent = True
        conn = self.HTTP_CONN

        # Try a normal chunked request (with extensions)
        body = ntob('8;key=value\r\nxx\r\nxxxx\r\n5\r\nyyyyy\r\n0\r\n'
                    'Content-Type: application/json\r\n'
                    '\r\n')
        conn.putrequest('POST', '/upload', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.putheader('Transfer-Encoding', 'chunked')
        conn.putheader('Trailer', 'Content-Type')
        # Note that this is somewhat malformed:
        # we shouldn't be sending Content-Length.
        # RFC 2616 says the server should ignore it.
        conn.putheader('Content-Length', '3')
        conn.endheaders()
        conn.send(body)
        response = conn.getresponse()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus('200 OK')
        self.assertBody("thanks for '%s'" % ntob('xx\r\nxxxxyyyyy'))

        # Try a chunked request that exceeds server.max_request_body_size.
        # Note that the delimiters and trailer are included.
        body = ntob('3e3\r\n' + ('x' * 995) + '\r\n0\r\n\r\n')
        conn.putrequest('POST', '/upload', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.putheader('Transfer-Encoding', 'chunked')
        conn.putheader('Content-Type', 'text/plain')
        # Chunked requests don't need a content-length
        ##        conn.putheader("Content-Length", len(body))
        conn.endheaders()
        conn.send(body)
        response = conn.getresponse()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus(413)
        conn.close()
예제 #9
0
    def test_100_Continue(self):
        if cherrypy.server.protocol_version != "HTTP/1.1":
            return self.skip()

        self.PROTOCOL = "HTTP/1.1"

        self.persistent = True
        conn = self.HTTP_CONN

        # Try a page without an Expect request header first.
        # Note that httplib's response.begin automatically ignores
        # 100 Continue responses, so we must manually check for it.
        try:
            conn.putrequest("POST", "/upload", skip_host=True)
            conn.putheader("Host", self.HOST)
            conn.putheader("Content-Type", "text/plain")
            conn.putheader("Content-Length", "4")
            conn.endheaders()
            conn.send(ntob("d'oh"))
            response = conn.response_class(conn.sock, method="POST")
            version, status, reason = response._read_status()
            self.assertNotEqual(status, 100)
        finally:
            conn.close()

        # Now try a page with an Expect header...
        try:
            conn.connect()
            conn.putrequest("POST", "/upload", skip_host=True)
            conn.putheader("Host", self.HOST)
            conn.putheader("Content-Type", "text/plain")
            conn.putheader("Content-Length", "17")
            conn.putheader("Expect", "100-continue")
            conn.endheaders()
            response = conn.response_class(conn.sock, method="POST")

            # ...assert and then skip the 100 response
            version, status, reason = response._read_status()
            self.assertEqual(status, 100)
            while True:
                line = response.fp.readline().strip()
                if line:
                    self.fail(
                        "100 Continue should not output any headers. Got %r" %
                        line)
                else:
                    break

            # ...send the body
            body = ntob("I am a small file")
            conn.send(body)

            # ...get the final response
            response.begin()
            self.status, self.headers, self.body = webtest.shb(response)
            self.assertStatus(200)
            self.assertBody("thanks for '%s'" % body)
        finally:
            conn.close()
예제 #10
0
    def test_100_Continue(self):
        if cherrypy.server.protocol_version != "HTTP/1.1":
            return self.skip()

        self.PROTOCOL = "HTTP/1.1"

        self.persistent = True
        conn = self.HTTP_CONN

        # Try a page without an Expect request header first.
        # Note that httplib's response.begin automatically ignores
        # 100 Continue responses, so we must manually check for it.
        try:
            conn.putrequest("POST", "/upload", skip_host=True)
            conn.putheader("Host", self.HOST)
            conn.putheader("Content-Type", "text/plain")
            conn.putheader("Content-Length", "4")
            conn.endheaders()
            conn.send(ntob("d'oh"))
            response = conn.response_class(conn.sock, method="POST")
            version, status, reason = response._read_status()
            self.assertNotEqual(status, 100)
        finally:
            conn.close()

        # Now try a page with an Expect header...
        try:
            conn.connect()
            conn.putrequest("POST", "/upload", skip_host=True)
            conn.putheader("Host", self.HOST)
            conn.putheader("Content-Type", "text/plain")
            conn.putheader("Content-Length", "17")
            conn.putheader("Expect", "100-continue")
            conn.endheaders()
            response = conn.response_class(conn.sock, method="POST")

            # ...assert and then skip the 100 response
            version, status, reason = response._read_status()
            self.assertEqual(status, 100)
            while True:
                line = response.fp.readline().strip()
                if line:
                    self.fail(
                        "100 Continue should not output any headers. Got %r" %
                        line)
                else:
                    break

            # ...send the body
            body = ntob("I am a small file")
            conn.send(body)

            # ...get the final response
            response.begin()
            self.status, self.headers, self.body = webtest.shb(response)
            self.assertStatus(200)
            self.assertBody("thanks for '%s'" % body)
        finally:
            conn.close()
예제 #11
0
 def test_Content_Length_out_preheaders(self):
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest('GET', '/custom_cl?body=I+have+too+many+bytes&cl=5', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(500)
     self.assertBody('The requested resource returned more bytes than the declared Content-Length.')
     conn.close()
예제 #12
0
 def test_Content_Length_out_postheaders(self):
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest('GET', '/custom_cl?body=I+too&body=+have+too+many&cl=5', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(200)
     self.assertBody('I too')
     conn.close()
예제 #13
0
 def test_Content_Length_out_postheaders(self):
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest('GET',
                     '/custom_cl?body=I+too&body=+have+too+many&cl=5',
                     skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(200)
     self.assertBody('I too')
     conn.close()
예제 #14
0
 def test_Content_Length_out_postheaders(self):
     # Try a non-chunked response where Content-Length is less than
     # the actual bytes in the response body.
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest("GET", "/custom_cl?body=I+too&body=+have+too+many&cl=5", skip_host=True)
     conn.putheader("Host", self.HOST)
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(200)
     self.assertBody("I too")
     conn.close()
예제 #15
0
 def test_Content_Length_in(self):
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest('POST', '/upload', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.putheader('Content-Type', 'text/plain')
     conn.putheader('Content-Length', '9999')
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(413)
     self.assertBody('The entity sent with the request exceeds the maximum allowed bytes.')
     conn.close()
예제 #16
0
 def test_Content_Length_out_preheaders(self):
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest('GET',
                     '/custom_cl?body=I+have+too+many+bytes&cl=5',
                     skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(500)
     self.assertBody(
         'The requested resource returned more bytes than the declared Content-Length.'
     )
     conn.close()
예제 #17
0
 def test_Content_Length_in(self):
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest('POST', '/upload', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.putheader('Content-Type', 'text/plain')
     conn.putheader('Content-Length', '9999')
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(413)
     self.assertBody(
         'The entity sent with the request exceeds the maximum allowed bytes.'
     )
     conn.close()
예제 #18
0
파일: test_conn.py 프로젝트: cread/ec2id
 def test_Content_Length(self):
     # Try a non-chunked request where Content-Length exceeds
     # server.max_request_body_size. Assert error before body send.
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest("POST", "/upload", skip_host=True)
     conn.putheader("Host", self.HOST)
     conn.putheader("Content-Type", "text/plain")
     conn.putheader("Content-Length", 9999)
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(413)
     self.assertBody("")
     conn.close()
예제 #19
0
 def test_Content_Length_out_postheaders(self):
     # Try a non-chunked response where Content-Length is less than
     # the actual bytes in the response body.
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest("GET",
                     "/custom_cl?body=I+too&body=+have+too+many&cl=5",
                     skip_host=True)
     conn.putheader("Host", self.HOST)
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(200)
     self.assertBody("I too")
     conn.close()
예제 #20
0
 def test_Content_Length(self):
     # Try a non-chunked request where Content-Length exceeds
     # server.max_request_body_size. Assert error before body send.
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest("POST", "/upload", skip_host=True)
     conn.putheader("Host", self.HOST)
     conn.putheader("Content-Type", "text/plain")
     conn.putheader("Content-Length", "9999")
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(413)
     self.assertBody("")
     conn.close()
 def test_Content_Length_in(self):
     # Try a non-chunked request where Content-Length exceeds
     # server.max_request_body_size. Assert error before body send.
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest('POST', '/upload', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.putheader('Content-Type', 'text/plain')
     conn.putheader('Content-Length', '9999')
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(413)
     self.assertBody('The entity sent with the request exceeds '
                     'the maximum allowed bytes.')
     conn.close()
예제 #22
0
 def test_Content_Length_in(self):
     # Try a non-chunked request where Content-Length exceeds
     # server.max_request_body_size. Assert error before body send.
     self.persistent = True
     conn = self.HTTP_CONN
     conn.putrequest('POST', '/upload', skip_host=True)
     conn.putheader('Host', self.HOST)
     conn.putheader('Content-Type', 'text/plain')
     conn.putheader('Content-Length', '9999')
     conn.endheaders()
     response = conn.getresponse()
     self.status, self.headers, self.body = webtest.shb(response)
     self.assertStatus(413)
     self.assertBody('The entity sent with the request exceeds '
                     'the maximum allowed bytes.')
     conn.close()
예제 #23
0
    def test_100_Continue(self):
        if cherrypy.server.protocol_version != 'HTTP/1.1':
            return self.skip()
        self.PROTOCOL = 'HTTP/1.1'
        self.persistent = True
        conn = self.HTTP_CONN
        conn.putrequest('POST', '/upload', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.putheader('Content-Type', 'text/plain')
        conn.putheader('Content-Length', '4')
        conn.endheaders()
        conn.send(ntob("d'oh"))
        response = conn.response_class(conn.sock, method='POST')
        version, status, reason = response._read_status()
        self.assertNotEqual(status, 100)
        conn.close()
        conn.connect()
        conn.putrequest('POST', '/upload', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.putheader('Content-Type', 'text/plain')
        conn.putheader('Content-Length', '17')
        conn.putheader('Expect', '100-continue')
        conn.endheaders()
        response = conn.response_class(conn.sock, method='POST')
        version, status, reason = response._read_status()
        self.assertEqual(status, 100)
        while True:
            line = response.fp.readline().strip()
            if line:
                self.fail(
                    '100 Continue should not output any headers. Got %r' %
                    line)
            else:
                break

        body = ntob('I am a small file')
        conn.send(body)
        response.begin()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus(200)
        self.assertBody("thanks for '%s'" % body)
        conn.close()
예제 #24
0
    def test_100_Continue(self):
        if cherrypy.server.protocol_version != 'HTTP/1.1':
            return self.skip()
        self.PROTOCOL = 'HTTP/1.1'
        self.persistent = True
        conn = self.HTTP_CONN
        conn.putrequest('POST', '/upload', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.putheader('Content-Type', 'text/plain')
        conn.putheader('Content-Length', '4')
        conn.endheaders()
        conn.send(ntob("d'oh"))
        response = conn.response_class(conn.sock, method='POST')
        version, status, reason = response._read_status()
        self.assertNotEqual(status, 100)
        conn.close()
        conn.connect()
        conn.putrequest('POST', '/upload', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.putheader('Content-Type', 'text/plain')
        conn.putheader('Content-Length', '17')
        conn.putheader('Expect', '100-continue')
        conn.endheaders()
        response = conn.response_class(conn.sock, method='POST')
        version, status, reason = response._read_status()
        self.assertEqual(status, 100)
        while True:
            line = response.fp.readline().strip()
            if line:
                self.fail('100 Continue should not output any headers. Got %r' % line)
            else:
                break

        body = ntob('I am a small file')
        conn.send(body)
        response.begin()
        self.status, self.headers, self.body = webtest.shb(response)
        self.assertStatus(200)
        self.assertBody("thanks for '%s'" % body)
        conn.close()
예제 #25
0
파일: test_conn.py 프로젝트: cread/ec2id
 def test_readall_or_close(self):
     if cherrypy.server.protocol_version != "HTTP/1.1":
         print "skipped ",
         return
     
     self.PROTOCOL = "HTTP/1.1"
     
     if self.scheme == "https":
         self.HTTP_CONN = httplib.HTTPSConnection
     else:
         self.HTTP_CONN = httplib.HTTPConnection
     
     # Test a max of 0 (the default) and then reset to what it was above.
     old_max = cherrypy.server.max_request_body_size
     for new_max in (0, old_max):
         cherrypy.server.max_request_body_size = new_max
         
         self.persistent = True
         conn = self.HTTP_CONN
         
         # Get a POST page with an error
         conn.putrequest("POST", "/err_before_read", skip_host=True)
         conn.putheader("Host", self.HOST)
         conn.putheader("Content-Type", "text/plain")
         conn.putheader("Content-Length", "1000")
         conn.putheader("Expect", "100-continue")
         conn.endheaders()
         response = conn.response_class(conn.sock, method="POST")
         
         # ...assert and then skip the 100 response
         version, status, reason = response._read_status()
         self.assertEqual(status, 100)
         while True:
             skip = response.fp.readline().strip()
             if not skip:
                 break
         
         # ...send the body
         conn.send("x" * 1000)
         
         # ...get the final response
         response.begin()
         self.status, self.headers, self.body = webtest.shb(response)
         self.assertStatus(500)
         
         # Now try a working page with an Expect header...
         conn._output('POST /upload HTTP/1.1')
         conn._output("Host: %s" % self.HOST)
         conn._output("Content-Type: text/plain")
         conn._output("Content-Length: 17")
         conn._output("Expect: 100-continue")
         conn._send_output()
         response = conn.response_class(conn.sock, method="POST")
         
         # ...assert and then skip the 100 response
         version, status, reason = response._read_status()
         self.assertEqual(status, 100)
         while True:
             skip = response.fp.readline().strip()
             if not skip:
                 break
         
         # ...send the body
         conn.send("I am a small file")
         
         # ...get the final response
         response.begin()
         self.status, self.headers, self.body = webtest.shb(response)
         self.assertStatus(200)
         self.assertBody("thanks for 'I am a small file' (text/plain)")
         conn.close()
예제 #26
0
    def test_readall_or_close(self):
        if cherrypy.server.protocol_version != "HTTP/1.1":
            return self.skip()

        self.PROTOCOL = "HTTP/1.1"

        if self.scheme == "https":
            self.HTTP_CONN = HTTPSConnection
        else:
            self.HTTP_CONN = HTTPConnection

        # Test a max of 0 (the default) and then reset to what it was above.
        old_max = cherrypy.server.max_request_body_size
        for new_max in (0, old_max):
            cherrypy.server.max_request_body_size = new_max

            self.persistent = True
            conn = self.HTTP_CONN

            # Get a POST page with an error
            conn.putrequest("POST", "/err_before_read", skip_host=True)
            conn.putheader("Host", self.HOST)
            conn.putheader("Content-Type", "text/plain")
            conn.putheader("Content-Length", "1000")
            conn.putheader("Expect", "100-continue")
            conn.endheaders()
            response = conn.response_class(conn.sock, method="POST")

            # ...assert and then skip the 100 response
            version, status, reason = response._read_status()
            self.assertEqual(status, 100)
            while True:
                skip = response.fp.readline().strip()
                if not skip:
                    break

            # ...send the body
            conn.send(ntob("x" * 1000))

            # ...get the final response
            response.begin()
            self.status, self.headers, self.body = webtest.shb(response)
            self.assertStatus(500)

            # Now try a working page with an Expect header...
            conn._output(ntob('POST /upload HTTP/1.1'))
            conn._output(ntob("Host: %s" % self.HOST, 'ascii'))
            conn._output(ntob("Content-Type: text/plain"))
            conn._output(ntob("Content-Length: 17"))
            conn._output(ntob("Expect: 100-continue"))
            conn._send_output()
            response = conn.response_class(conn.sock, method="POST")

            # ...assert and then skip the 100 response
            version, status, reason = response._read_status()
            self.assertEqual(status, 100)
            while True:
                skip = response.fp.readline().strip()
                if not skip:
                    break

            # ...send the body
            body = ntob("I am a small file")
            conn.send(body)

            # ...get the final response
            response.begin()
            self.status, self.headers, self.body = webtest.shb(response)
            self.assertStatus(200)
            self.assertBody("thanks for '%s'" % body)
            conn.close()