nxt_python_asgi_http.c (1916:2d7e54265010) nxt_python_asgi_http.c (1917:a7e80c97def4)
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6
7#include <python/nxt_python.h>
8

--- 25 unchanged lines hidden (view full) ---

34static PyObject *nxt_py_asgi_http_receive(PyObject *self, PyObject *none);
35static PyObject *nxt_py_asgi_http_read_msg(nxt_py_asgi_http_t *http);
36static PyObject *nxt_py_asgi_http_send(PyObject *self, PyObject *dict);
37static PyObject *nxt_py_asgi_http_response_start(nxt_py_asgi_http_t *http,
38 PyObject *dict);
39static PyObject *nxt_py_asgi_http_response_body(nxt_py_asgi_http_t *http,
40 PyObject *dict);
41static void nxt_py_asgi_http_emit_disconnect(nxt_py_asgi_http_t *http);
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6
7#include <python/nxt_python.h>
8

--- 25 unchanged lines hidden (view full) ---

34static PyObject *nxt_py_asgi_http_receive(PyObject *self, PyObject *none);
35static PyObject *nxt_py_asgi_http_read_msg(nxt_py_asgi_http_t *http);
36static PyObject *nxt_py_asgi_http_send(PyObject *self, PyObject *dict);
37static PyObject *nxt_py_asgi_http_response_start(nxt_py_asgi_http_t *http,
38 PyObject *dict);
39static PyObject *nxt_py_asgi_http_response_body(nxt_py_asgi_http_t *http,
40 PyObject *dict);
41static void nxt_py_asgi_http_emit_disconnect(nxt_py_asgi_http_t *http);
42static void nxt_py_asgi_http_set_result(nxt_py_asgi_http_t *http,
43 PyObject *future, PyObject *msg);
42static PyObject *nxt_py_asgi_http_done(PyObject *self, PyObject *future);
43
44
45static PyMethodDef nxt_py_asgi_http_methods[] = {
46 { "receive", nxt_py_asgi_http_receive, METH_NOARGS, 0 },
47 { "send", nxt_py_asgi_http_send, METH_O, 0 },
48 { "_done", nxt_py_asgi_http_done, METH_O, 0 },
49 { NULL, NULL, 0, 0 }

--- 410 unchanged lines hidden (view full) ---

460 Py_INCREF(http);
461 return (PyObject *) http;
462}
463
464
465static void
466nxt_py_asgi_http_emit_disconnect(nxt_py_asgi_http_t *http)
467{
44static PyObject *nxt_py_asgi_http_done(PyObject *self, PyObject *future);
45
46
47static PyMethodDef nxt_py_asgi_http_methods[] = {
48 { "receive", nxt_py_asgi_http_receive, METH_NOARGS, 0 },
49 { "send", nxt_py_asgi_http_send, METH_O, 0 },
50 { "_done", nxt_py_asgi_http_done, METH_O, 0 },
51 { NULL, NULL, 0, 0 }

--- 410 unchanged lines hidden (view full) ---

462 Py_INCREF(http);
463 return (PyObject *) http;
464}
465
466
467static void
468nxt_py_asgi_http_emit_disconnect(nxt_py_asgi_http_t *http)
469{
468 PyObject *msg, *future, *res;
470 PyObject *msg, *future;
469
470 if (http->receive_future == NULL) {
471 return;
472 }
473
474 msg = nxt_py_asgi_new_msg(http->req, nxt_py_http_disconnect_str);
475 if (nxt_slow_path(msg == NULL)) {
476 return;
477 }
478
479 if (msg == Py_None) {
480 Py_DECREF(msg);
481 return;
482 }
483
484 future = http->receive_future;
485 http->receive_future = NULL;
486
471
472 if (http->receive_future == NULL) {
473 return;
474 }
475
476 msg = nxt_py_asgi_new_msg(http->req, nxt_py_http_disconnect_str);
477 if (nxt_slow_path(msg == NULL)) {
478 return;
479 }
480
481 if (msg == Py_None) {
482 Py_DECREF(msg);
483 return;
484 }
485
486 future = http->receive_future;
487 http->receive_future = NULL;
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
495static void
496nxt_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 if (nxt_slow_path(res == NULL)) {
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 nxt_python_print_exception();
491 }
492
504 nxt_python_print_exception();
505 }
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 Py_XDECREF(res);
494 Py_DECREF(future);
519 Py_XDECREF(res);
520 Py_DECREF(future);
495
496 Py_DECREF(msg);
497}
498
499
500void
501nxt_py_asgi_http_data_handler(nxt_unit_request_info_t *req)
502{
521}
522
523
524void
525nxt_py_asgi_http_data_handler(nxt_unit_request_info_t *req)
526{
503 PyObject *msg, *future, *res;
527 PyObject *msg, *future;
504 nxt_py_asgi_http_t *http;
505
506 http = req->data;
507
508 nxt_unit_req_debug(req, "asgi_http_data_handler");
509
510 if (http->receive_future == NULL) {
511 return;

--- 7 unchanged lines hidden (view full) ---

519 if (msg == Py_None) {
520 Py_DECREF(msg);
521 return;
522 }
523
524 future = http->receive_future;
525 http->receive_future = NULL;
526
528 nxt_py_asgi_http_t *http;
529
530 http = req->data;
531
532 nxt_unit_req_debug(req, "asgi_http_data_handler");
533
534 if (http->receive_future == NULL) {
535 return;

--- 7 unchanged lines hidden (view full) ---

543 if (msg == Py_None) {
544 Py_DECREF(msg);
545 return;
546 }
547
548 future = http->receive_future;
549 http->receive_future = NULL;
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 }
551 nxt_py_asgi_http_set_result(http, future, msg);
532
552
533 Py_XDECREF(res);
534 Py_DECREF(future);
535
536 Py_DECREF(msg);
537}
538
539
540int
541nxt_py_asgi_http_drain(nxt_queue_link_t *lnk)
542{
543 char *body_str;

--- 26 unchanged lines hidden (view full) ---

570 http->bytes_sent += sent;
571 }
572
573 Py_CLEAR(http->send_body);
574
575 future = http->send_future;
576 http->send_future = NULL;
577
553 Py_DECREF(msg);
554}
555
556
557int
558nxt_py_asgi_http_drain(nxt_queue_link_t *lnk)
559{
560 char *body_str;

--- 26 unchanged lines hidden (view full) ---

587 http->bytes_sent += sent;
588 }
589
590 Py_CLEAR(http->send_body);
591
592 future = http->send_future;
593 http->send_future = NULL;
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 }
595 nxt_py_asgi_http_set_result(http, future, Py_None);
584
596
585 Py_XDECREF(res);
586 Py_DECREF(future);
587
588 return NXT_UNIT_OK;
589
590fail:
591
592 exc = PyObject_CallFunctionObjArgs(PyExc_RuntimeError,
593 nxt_py_failed_to_send_body_str,
594 NULL);
595 if (nxt_slow_path(exc == NULL)) {

--- 76 unchanged lines hidden ---
597 return NXT_UNIT_OK;
598
599fail:
600
601 exc = PyObject_CallFunctionObjArgs(PyExc_RuntimeError,
602 nxt_py_failed_to_send_body_str,
603 NULL);
604 if (nxt_slow_path(exc == NULL)) {

--- 76 unchanged lines hidden ---