Permalink
Browse files

Add new http status 451

  • Loading branch information...
sinwoobang committed Dec 22, 2015
1 parent d513897 commit 6d58abf7a62edd89cfb21975a6fb4d62494ce003
Showing with 20 additions and 0 deletions.
  1. +13 −0 aiohttp/web_exceptions.py
  2. +7 −0 tests/test_web_exceptions.py
View
@@ -45,6 +45,7 @@
'HTTPPreconditionRequired',
'HTTPTooManyRequests',
'HTTPRequestHeaderFieldsTooLarge',
'HTTPUnavailableForLegalReasons',
'HTTPServerError',
'HTTPInternalServerError',
'HTTPNotImplemented',
@@ -286,6 +287,18 @@ class HTTPRequestHeaderFieldsTooLarge(HTTPClientError):
status_code = 431
class HTTPUnavailableForLegalReasons(HTTPClientError):
status_code = 451
def __init__(self, link=None, *, headers=None, reason=None,
body=None, text=None, content_type=None):
super().__init__(headers=headers, reason=reason,
body=body, text=text, content_type=content_type)
if link:
self.headers['Link'] = '<%s>; rel="blocked-by"' % link
self.link = link
############################################################
# 5xx Server Error
############################################################
@@ -163,3 +163,10 @@ def test_empty_body_205():
def test_empty_body_304():
resp = web.HTTPNoContent()
resp.body is None
def test_link_header_451(buf, request):
resp = web.HTTPUnavailableForLegalReasons(link='http://warning.or.kr/')
assert 'http://warning.or.kr/' == resp.link
assert '<http://warning.or.kr/>; rel="blocked-by"' == resp.headers['Link']

0 comments on commit 6d58abf

Please sign in to comment.