本文整理匯總了Python中gunicorn.http.wsgi.Response.default_headers方法的典型用法代碼示例。如果您正苦於以下問題:Python Response.default_headers方法的具體用法?Python Response.default_headers怎麽用?Python Response.default_headers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gunicorn.http.wsgi.Response
的用法示例。
在下文中一共展示了Response.default_headers方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_http_header_encoding
# 需要導入模塊: from gunicorn.http.wsgi import Response [as 別名]
# 或者: from gunicorn.http.wsgi.Response import default_headers [as 別名]
def test_http_header_encoding():
""" tests whether http response headers are USASCII encoded """
mocked_socket = mock.MagicMock()
mocked_socket.sendall = mock.MagicMock()
mocked_request = mock.MagicMock()
response = Response(mocked_request, mocked_socket, None)
# set umlaut header value - latin-1 is OK
response.headers.append(('foo', 'häder'))
response.send_headers()
# set a-breve header value - unicode, non-latin-1 fails
response = Response(mocked_request, mocked_socket, None)
response.headers.append(('apple', 'măr'))
with pytest.raises(UnicodeEncodeError):
response.send_headers()
# build our own header_str to compare against
tosend = response.default_headers()
tosend.extend(["%s: %s\r\n" % (k, v) for k, v in response.headers])
header_str = "%s\r\n" % "".join(tosend)
with pytest.raises(UnicodeEncodeError):
mocked_socket.sendall(util.to_bytestring(header_str, "ascii"))
示例2: test_http_header_encoding
# 需要導入模塊: from gunicorn.http.wsgi import Response [as 別名]
# 或者: from gunicorn.http.wsgi.Response import default_headers [as 別名]
def test_http_header_encoding():
""" tests whether http response headers are USASCII encoded """
mocked_socket = mock.MagicMock()
mocked_socket.sendall = mock.MagicMock()
mocked_request = mock.MagicMock()
response = Response(mocked_request, mocked_socket, None)
# set umlaut header
response.headers.append(('foo', 'häder'))
try:
response.send_headers()
except Exception as e:
assert isinstance(e, UnicodeEncodeError)
# build our own header_str to compare against
tosend = response.default_headers()
tosend.extend(["%s: %s\r\n" % (k, v) for k, v in response.headers])
header_str = "%s\r\n" % "".join(tosend)
try:
mocked_socket.sendall(util.to_bytestring(header_str,"ascii"))
except Exception as e:
assert isinstance(e, UnicodeEncodeError)
示例3: test_http_header_encoding
# 需要導入模塊: from gunicorn.http.wsgi import Response [as 別名]
# 或者: from gunicorn.http.wsgi.Response import default_headers [as 別名]
def test_http_header_encoding():
""" tests whether http response headers are ISO-8859-1 encoded """
mocked_socket = mock.MagicMock()
mocked_socket.sendall = mock.MagicMock()
mocked_request = mock.MagicMock()
response = Response(mocked_request, mocked_socket, None)
# set umlaut header
response.headers.append(('foo', 'häder'))
response.send_headers()
# build our own header_str to compare against
tosend = response.default_headers()
tosend.extend(["%s: %s\r\n" % (k, v) for k, v in response.headers])
header_str = "%s\r\n" % "".join(tosend)
mocked_socket.sendall.assert_called_with(util.to_latin1(header_str))