comparison mercurial/httpclient/tests/test_bogus_responses.py @ 14243:861f28212398

Import new http library as mercurial.httpclient. This is revision a4229f13c374 of http://py-nonblocking-http.googlecode.com/ with a no-check-code comment added to the end of each file using `for fi in $(hg manifest | grep mercurial/httpclient/) ; echo '# no-check-code' >> $fi`.
author Augie Fackler <durin42@gmail.com>
date Fri, 06 May 2011 09:57:55 -0500
parents
children 24dbef11f477
comparison
equal deleted inserted replaced
14242:5ee1309f7edb 14243:861f28212398
1 # Copyright 2010, Google Inc.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 """Tests against malformed responses.
30
31 Server implementations that respond with only LF instead of CRLF have
32 been observed. Checking against ones that use only CR is a hedge
33 against that potential insanit.y
34 """
35 import unittest
36
37 import http
38
39 # relative import to ease embedding the library
40 import util
41
42
43 class SimpleHttpTest(util.HttpTestBase, unittest.TestCase):
44
45 def bogusEOL(self, eol):
46 con = http.HTTPConnection('1.2.3.4:80')
47 con._connect()
48 con.sock.data = ['HTTP/1.1 200 OK%s' % eol,
49 'Server: BogusServer 1.0%s' % eol,
50 'Content-Length: 10',
51 eol * 2,
52 '1234567890']
53 con.request('GET', '/')
54
55 expected_req = ('GET / HTTP/1.1\r\n'
56 'Host: 1.2.3.4\r\n'
57 'accept-encoding: identity\r\n\r\n')
58
59 self.assertEqual(('1.2.3.4', 80), con.sock.sa)
60 self.assertEqual(expected_req, con.sock.sent)
61 self.assertEqual('1234567890', con.getresponse().read())
62
63 def testOnlyLinefeed(self):
64 self.bogusEOL('\n')
65
66 def testOnlyCarriageReturn(self):
67 self.bogusEOL('\r')
68 # no-check-code