@@ -520,10 +520,8 @@ class Response:
520
520
:param body: The body of the response. If a dictionary or list is given,
521
521
a JSON formatter is used to generate the body. If a file-like
522
522
object or an async generator is given, a streaming response is
523
- used. If a string is given, it is encoded from UTF-8. If an
524
- integer is given and ``status_code`` isn't given, then the
525
- status code is assigned and the body is kept empty. Else, the
526
- body should be a byte sequence.
523
+ used. If a string is given, it is encoded from UTF-8. Else,
524
+ the body should be a byte sequence.
527
525
:param status_code: The numeric HTTP status code of the response. The
528
526
default is 200.
529
527
:param headers: A dictionary of headers to include in the response.
@@ -556,14 +554,11 @@ class Response:
556
554
#: written to the client. Used to exit WebSocket connections cleanly.
557
555
already_handled = None
558
556
559
- def __init__ (self , body = '' , status_code = None , headers = None , reason = None ):
560
- if body is None and status_code is None :
557
+ def __init__ (self , body = '' , status_code = 200 , headers = None , reason = None ):
558
+ if body is None and status_code == 200 :
561
559
body = ''
562
560
status_code = 204
563
- elif isinstance (body , int ) and status_code is None :
564
- status_code = int (body )
565
- body = ''
566
- self .status_code = status_code or 200
561
+ self .status_code = status_code
567
562
self .headers = NoCaseDict (headers or {})
568
563
self .reason = reason
569
564
if isinstance (body , (dict , list )):
@@ -1374,7 +1369,12 @@ async def dispatch_request(self, req):
1374
1369
if res is None :
1375
1370
res = await invoke_handler (
1376
1371
f , req , ** req .url_args )
1372
+ if isinstance (res , int ):
1373
+ res = '' , res
1377
1374
if isinstance (res , tuple ):
1375
+ if isinstance (res [0 ], int ):
1376
+ res = ('' , res [0 ],
1377
+ res [1 ] if len (res ) > 1 else {})
1378
1378
body = res [0 ]
1379
1379
if isinstance (res [1 ], int ):
1380
1380
status_code = res [1 ]
0 commit comments