@@ -39,6 +39,8 @@ static PyObject *nxt_py_asgi_http_response_start(nxt_py_asgi_http_t *http,
39
39
static PyObject * nxt_py_asgi_http_response_body (nxt_py_asgi_http_t * http ,
40
40
PyObject * dict );
41
41
static void nxt_py_asgi_http_emit_disconnect (nxt_py_asgi_http_t * http );
42
+ static void nxt_py_asgi_http_set_result (nxt_py_asgi_http_t * http ,
43
+ PyObject * future , PyObject * msg );
42
44
static PyObject * nxt_py_asgi_http_done (PyObject * self , PyObject * future );
43
45
44
46
@@ -465,7 +467,7 @@ nxt_py_asgi_http_response_body(nxt_py_asgi_http_t *http, PyObject *dict)
465
467
static void
466
468
nxt_py_asgi_http_emit_disconnect (nxt_py_asgi_http_t * http )
467
469
{
468
- PyObject * msg , * future , * res ;
470
+ PyObject * msg , * future ;
469
471
470
472
if (http -> receive_future == NULL ) {
471
473
return ;
@@ -484,23 +486,45 @@ nxt_py_asgi_http_emit_disconnect(nxt_py_asgi_http_t *http)
484
486
future = http -> receive_future ;
485
487
http -> receive_future = NULL ;
486
488
487
- res = PyObject_CallMethodObjArgs (future , nxt_py_set_result_str , msg , NULL );
489
+ nxt_py_asgi_http_set_result (http , future , msg );
490
+
491
+ Py_DECREF (msg );
492
+ }
493
+
494
+
495
+ static void
496
+ nxt_py_asgi_http_set_result (nxt_py_asgi_http_t * http , PyObject * future ,
497
+ PyObject * msg )
498
+ {
499
+ PyObject * res ;
500
+
501
+ res = PyObject_CallMethodObjArgs (future , nxt_py_done_str , NULL );
488
502
if (nxt_slow_path (res == NULL )) {
489
- nxt_unit_req_alert (http -> req , "'set_result ' call failed" );
503
+ nxt_unit_req_alert (http -> req , "'done ' call failed" );
490
504
nxt_python_print_exception ();
491
505
}
492
506
507
+ if (nxt_fast_path (res == Py_False )) {
508
+ res = PyObject_CallMethodObjArgs (future , nxt_py_set_result_str , msg ,
509
+ NULL );
510
+ if (nxt_slow_path (res == NULL )) {
511
+ nxt_unit_req_alert (http -> req , "'set_result' call failed" );
512
+ nxt_python_print_exception ();
513
+ }
514
+
515
+ } else {
516
+ res = NULL ;
517
+ }
518
+
493
519
Py_XDECREF (res );
494
520
Py_DECREF (future );
495
-
496
- Py_DECREF (msg );
497
521
}
498
522
499
523
500
524
void
501
525
nxt_py_asgi_http_data_handler (nxt_unit_request_info_t * req )
502
526
{
503
- PyObject * msg , * future , * res ;
527
+ PyObject * msg , * future ;
504
528
nxt_py_asgi_http_t * http ;
505
529
506
530
http = req -> data ;
@@ -524,14 +548,7 @@ nxt_py_asgi_http_data_handler(nxt_unit_request_info_t *req)
524
548
future = http -> receive_future ;
525
549
http -> receive_future = NULL ;
526
550
527
- res = PyObject_CallMethodObjArgs (future , nxt_py_set_result_str , msg , NULL );
528
- if (nxt_slow_path (res == NULL )) {
529
- nxt_unit_req_alert (req , "'set_result' call failed" );
530
- nxt_python_print_exception ();
531
- }
532
-
533
- Py_XDECREF (res );
534
- Py_DECREF (future );
551
+ nxt_py_asgi_http_set_result (http , future , msg );
535
552
536
553
Py_DECREF (msg );
537
554
}
@@ -575,15 +592,7 @@ nxt_py_asgi_http_drain(nxt_queue_link_t *lnk)
575
592
future = http -> send_future ;
576
593
http -> send_future = NULL ;
577
594
578
- res = PyObject_CallMethodObjArgs (future , nxt_py_set_result_str , Py_None ,
579
- NULL );
580
- if (nxt_slow_path (res == NULL )) {
581
- nxt_unit_req_alert (http -> req , "'set_result' call failed" );
582
- nxt_python_print_exception ();
583
- }
584
-
585
- Py_XDECREF (res );
586
- Py_DECREF (future );
595
+ nxt_py_asgi_http_set_result (http , future , Py_None );
587
596
588
597
return NXT_UNIT_OK ;
589
598
0 commit comments