예제 #1
0
 def test_raw_request_with_alternate_url(self):
 
     s = HttpSession(http_method='GET', http_url='http://google.com/')
     raw_request = s.get_raw_request('http://www.google.com/')
     expected_request = 'GET / HTTP/1.1\r\n' + \
         'Host: www.google.com\r\nAccept: */*\r\n\r\n'
     
     self.failUnlessEqual(raw_request, expected_request)
예제 #2
0
 def test_multiple_header_values(self):
     headers = '\r\n'.join([
         'Cache-Control: a',
         'Cache-Control: b',
     ])
     s = HttpSession(http_method='GET', http_url='http://localhost:9000/endpoint', http_headers=headers)
     
     request = s.get_raw_request()
     
     self.failUnless('Cache-Control: a' in request)
     self.failUnless('Cache-Control: b' in request)
예제 #3
0
 def test_raw_request_with_extra_headers(self):
     headers = '\r\n'.join([
         'User-Agent: Spyglass/0.1',
         'Referer: http://localhost:9000/login.jsp'
     ])
     s = HttpSession(http_method='GET', http_url='http://localhost:9000/endpoint', http_headers=headers)
          
     status, mime_headers, mime_body = self.parse_request(s.get_raw_request())
     
     self.failUnlessEqual(mime_headers['Host'], 'localhost')
     self.failUnlessEqual(mime_headers['User-Agent'], 'Spyglass/0.1')
     self.failUnlessEqual(mime_headers['Referer'], 'http://localhost:9000/login.jsp')
예제 #4
0
 def test_raw_request_with_host_headers(self):
     headers = '\r\n'.join([
         'User-Agent: Spyglass/0.1',
         'Referer: http://localhost:9000/login.jsp',
         'Host: google.com',
     ])
     s = HttpSession(http_method='GET', http_url='http://localhost:9000/endpoint', http_headers=headers)
     
     # this is a bit of a hack, but using the email parsing library
     # is way easier and more accurate than comparing strings
     status, mime_headers, mime_body = self.parse_request(s.get_raw_request())
     
     self.assertTrue('Host' in mime_headers)
     self.assertTrue(mime_headers['Host'] == 'google.com')
예제 #5
0
 def test_raw_request_with_body(self):
 
     body = '''
         <fake-xml>
             <key>com.bleedingwolf.PrincipalClass</key>
             <value>SomeClassName</value>
         </fake-xml>
     '''
     content_length = len(body)
     
     s = HttpSession(http_method='POST', http_url='http://localhost:9000/endpoint', http_body=body)
     
     expected_request = '''POST /endpoint HTTP/1.1\r\nHost: localhost\r\n''' + \
         '''Accept: */*\r\nContent-Length: %d\r\n\r\n%s''' % (content_length, body)
             
     self.failUnlessEqual(s.get_raw_request(), expected_request)
예제 #6
0
 def test_raw_request_with_extra_headers(self):
     headers = '\r\n'.join([
         'User-Agent: Spyglass/0.1',
         'Referer: http://localhost:9000/login.jsp'
     ])
     s = HttpSession(http_method='GET', http_url='http://localhost:9000/endpoint', http_headers=headers)
     
     expected_request = '\r\n'.join([
         'GET /endpoint HTTP/1.1',
         'Host: localhost',
         'Accept: */*',
         'User-Agent: Spyglass/0.1',
         'Referer: http://localhost:9000/login.jsp',
         '',
         '',
     ])
             
     self.failUnlessEqual(s.get_raw_request(), expected_request)
예제 #7
0
 def test_raw_request_with_body(self):
 
     import textwrap
 
     body = textwrap.dedent('''\
         <fake-xml>
             <key>com.bleedingwolf.PrincipalClass</key>
             <value>SomeClassName</value>
         </fake-xml>''')
     content_length = len(body)
     
     s = HttpSession(http_method='POST', http_url='http://localhost:9000/endpoint', http_body=body)
     
     expected_request = '''POST /endpoint HTTP/1.1\r\nHost: localhost\r\n''' + \
         '''Accept: */*\r\nContent-Length: %d\r\n\r\n%s''' % (content_length, body)
     
     status, mime_headers, mime_body = self.parse_request(s.get_raw_request())
            
     self.failUnlessEqual(mime_headers['Content-Length'], str(content_length))
     self.failUnlessEqual(mime_body, body)
예제 #8
0
 def test_raw_request_with_querystring(self):
 
     s = HttpSession(http_method='GET', http_url='http://api.flickr.com/services/rest/?method=flickr.photos.getExif')
     expected_request = 'GET /services/rest/?method=flickr.photos.getExif HTTP/1.1\r\n' + \
         'Host: api.flickr.com\r\nAccept: */*\r\n\r\n'
     self.failUnlessEqual(s.get_raw_request(), expected_request)
예제 #9
0
 def test_raw_request_for_index(self):
     
     s = HttpSession(http_method='GET', http_url='http://www.carfax.com')
     expected_request = 'GET / HTTP/1.1\r\nHost: www.carfax.com\r\nAccept: */*\r\n\r\n'
     self.failUnlessEqual(s.get_raw_request(), expected_request)
예제 #10
0
 def test_raw_request_with_path(self):
     
     s = HttpSession(http_method='GET', http_url='http://api.gowalla.com/spots')
     expected_request = 'GET /spots HTTP/1.1\r\nHost: api.gowalla.com\r\nAccept: */*\r\n\r\n'
     self.failUnlessEqual(s.get_raw_request(), expected_request)