self.proxy_port = proxy_port
self.proxy_username = proxy_username
self.proxy_password = proxy_password
- self.url = utf8(url)
+ self.url = url
self.method = method
self.headers = headers
self.body = utf8(body)
- self.auth_username = utf8(auth_username)
- self.auth_password = utf8(auth_password)
+ self.auth_username = auth_username
+ self.auth_password = auth_password
self.connect_timeout = connect_timeout
self.request_timeout = request_timeout
self.follow_redirects = follow_redirects
#!/usr/bin/env python
from __future__ import with_statement
-from tornado.escape import utf8, _unicode
+from tornado.escape import utf8, _unicode, native_str
from tornado.httpclient import HTTPRequest, HTTPResponse, HTTPError, AsyncHTTPClient
from tornado.httputil import HTTPHeaders
from tornado.ioloop import IOLoop
error=HTTPError(599, "Connection closed")))
def _on_headers(self, data):
- data = data.decode("latin1")
+ data = native_str(data.decode("latin1"))
first_line, _, header_data = data.partition("\r\n")
match = re.match("HTTP/1.[01] ([0-9]+)", first_line)
assert match
self.code in (301, 302)):
new_request = copy.copy(self.request)
new_request.url = urlparse.urljoin(self.request.url,
- utf8(self.headers["Location"]))
+ self.headers["Location"])
new_request.max_redirects -= 1
del new_request.headers["Host"]
new_request.original_request = original_request
from tornado.escape import utf8
from tornado.httpclient import AsyncHTTPClient
from tornado.testing import AsyncHTTPTestCase, LogTrapTestCase, get_unused_port
-from tornado.util import b
+from tornado.util import b, bytes_type
from tornado.web import Application, RequestHandler, asynchronous, url
class HelloWorldHandler(RequestHandler):
response = self.fetch("/countdown/2")
self.assertEqual(200, response.code)
- self.assertTrue(response.effective_url.endswith(b("/countdown/0")))
+ self.assertTrue(response.effective_url.endswith("/countdown/0"))
self.assertEqual(b("Zero"), response.body)
def test_max_redirects(self):
self.assertEqual(302, response.code)
# We requested 5, followed three redirects for 4, 3, 2, then the last
# unfollowed redirect is to 1.
- self.assertTrue(response.request.url.endswith(b("/countdown/5")))
- self.assertTrue(response.effective_url.endswith(b("/countdown/2")))
+ self.assertTrue(response.request.url.endswith("/countdown/5"))
+ self.assertTrue(response.effective_url.endswith("/countdown/2"))
self.assertTrue(response.headers["Location"].endswith("/countdown/1"))
def test_credentials_in_url(self):
self.http_client.fetch(url, self.stop, allow_ipv6=True)
response = self.wait()
self.assertEqual(response.body, b("Hello world!"))
+
+ def test_types(self):
+ response = self.fetch("/hello")
+ self.assertEqual(type(response.body), bytes_type)
+ self.assertEqual(type(response.headers["Content-Type"]), str)
+ self.assertEqual(type(response.code), int)
+ self.assertEqual(type(response.effective_url), str)