Skip to content

Commit

Permalink
Merge pull request #697 from sinwoobang/master
Browse files Browse the repository at this point in the history
Add new approved http status 451
  • Loading branch information
asvetlov committed Mar 2, 2016
2 parents 6e8b3ae + 6d58abf commit dfaa747
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aiohttp/web_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'HTTPPreconditionRequired',
'HTTPTooManyRequests',
'HTTPRequestHeaderFieldsTooLarge',
'HTTPUnavailableForLegalReasons',
'HTTPServerError',
'HTTPInternalServerError',
'HTTPNotImplemented',
Expand Down Expand Up @@ -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
############################################################
Expand Down
7 changes: 7 additions & 0 deletions tests/test_web_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 dfaa747

Please sign in to comment.