Skip to content

Commit dfaa747

Browse files
committed
Merge pull request #697 from sinwoobang/master
Add new approved http status 451
2 parents 6e8b3ae + 6d58abf commit dfaa747

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

aiohttp/web_exceptions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
'HTTPPreconditionRequired',
4646
'HTTPTooManyRequests',
4747
'HTTPRequestHeaderFieldsTooLarge',
48+
'HTTPUnavailableForLegalReasons',
4849
'HTTPServerError',
4950
'HTTPInternalServerError',
5051
'HTTPNotImplemented',
@@ -286,6 +287,18 @@ class HTTPRequestHeaderFieldsTooLarge(HTTPClientError):
286287
status_code = 431
287288

288289

290+
class HTTPUnavailableForLegalReasons(HTTPClientError):
291+
status_code = 451
292+
293+
def __init__(self, link=None, *, headers=None, reason=None,
294+
body=None, text=None, content_type=None):
295+
super().__init__(headers=headers, reason=reason,
296+
body=body, text=text, content_type=content_type)
297+
if link:
298+
self.headers['Link'] = '<%s>; rel="blocked-by"' % link
299+
self.link = link
300+
301+
289302
############################################################
290303
# 5xx Server Error
291304
############################################################

tests/test_web_exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,10 @@ def test_empty_body_205():
163163
def test_empty_body_304():
164164
resp = web.HTTPNoContent()
165165
resp.body is None
166+
167+
168+
def test_link_header_451(buf, request):
169+
resp = web.HTTPUnavailableForLegalReasons(link='http://warning.or.kr/')
170+
171+
assert 'http://warning.or.kr/' == resp.link
172+
assert '<http://warning.or.kr/>; rel="blocked-by"' == resp.headers['Link']

0 commit comments

Comments
 (0)