Lines Matching refs:r

79 	request_st *r;  member
198 static void mod_cgi_patch_config(request_st * const r, plugin_data * const p) { in mod_cgi_patch_config() argument
202 if (config_check_cond(r, (uint32_t)p->cvlist[i].k_id)) in mod_cgi_patch_config()
439 request_st * const r = hctx->r; in cgi_connection_close() local
440 r->plugin_ctx[p->id] = NULL; in cgi_connection_close()
449 if (r->handler_module == p->self) { in cgi_connection_close()
450 http_response_backend_done(r); in cgi_connection_close()
454 static handler_t cgi_connection_close_callback(request_st * const r, void *p_d) { in cgi_connection_close_callback() argument
455 handler_ctx *hctx = r->plugin_ctx[((plugin_data *)p_d)->id]; in cgi_connection_close_callback()
457 chunkqueue_set_tempdirs(&r->reqbody_queue, /* reset sz */ in cgi_connection_close_callback()
458 r->reqbody_queue.tempdirs, 0); in cgi_connection_close_callback()
476 static handler_t cgi_process_wr_revents (handler_ctx * const hctx, request_st * const r, int revent… in cgi_process_wr_revents() argument
487 if (r->reqbody_length) { in cgi_process_wr_revents()
488 chunkqueue *cq = &r->reqbody_queue; in cgi_process_wr_revents()
490 if (cq->bytes_in != (off_t)r->reqbody_length) { in cgi_process_wr_revents()
491 r->keep_alive = 0; in cgi_process_wr_revents()
499 log_error(r->conf.errh, __FILE__, __LINE__, "cgi-FDEVENT_ERR"); in cgi_process_wr_revents()
509 static handler_t cgi_response_headers(request_st * const r, struct http_response_opts_t *opts) { in cgi_response_headers() argument
513 if (light_btst(r->resp_htags, HTTP_HEADER_UPGRADE)) { in cgi_response_headers()
514 if (hctx->conf.upgrade && r->http_status == 101) { in cgi_response_headers()
516 if (r->h2_connect_ext) { in cgi_response_headers()
517 r->http_status = 200; /* OK (response status for CONNECT) */ in cgi_response_headers()
518 http_header_response_unset(r, HTTP_HEADER_UPGRADE, in cgi_response_headers()
520 http_header_response_unset(r, HTTP_HEADER_OTHER, in cgi_response_headers()
523 http_response_upgrade_read_body_unknown(r); in cgi_response_headers()
526 light_bclr(r->resp_htags, HTTP_HEADER_UPGRADE); in cgi_response_headers()
531 http_header_response_unset(r, HTTP_HEADER_UPGRADE, in cgi_response_headers()
536 else if (__builtin_expect( (r->h2_connect_ext != 0), 0) in cgi_response_headers()
537 && r->http_status < 300) { in cgi_response_headers()
539 http_response_body_clear(r, 0); in cgi_response_headers()
540 r->handler_module = NULL; in cgi_response_headers()
541 r->http_status = 405; /* Method Not Allowed */ in cgi_response_headers()
546 && !light_btst(r->resp_htags, HTTP_HEADER_UPGRADE)) { in cgi_response_headers()
547 chunkqueue *cq = &r->reqbody_queue; in cgi_response_headers()
549 r->reqbody_length = hctx->orig_reqbody_length; in cgi_response_headers()
550 if (cq->bytes_out == (off_t)r->reqbody_length) { in cgi_response_headers()
561 static handler_t cgi_local_redir(request_st * const r, handler_ctx * const hctx) { in cgi_local_redir() argument
564 http_response_reset(r); /*(includes r->http_status = 0)*/ in cgi_local_redir()
565 r->con->srv->plugins_request_reset(r); in cgi_local_redir()
571 static int cgi_recv_response(request_st * const r, handler_ctx * const hctx) { in cgi_recv_response() argument
572 const off_t bytes_in = r->write_queue.bytes_in; in cgi_recv_response()
573 switch (http_response_read(r, &hctx->opts, in cgi_recv_response()
576 if (r->write_queue.bytes_in > bytes_in) in cgi_recv_response()
580 http_response_backend_error(r); in cgi_recv_response()
586 return cgi_local_redir(r, hctx); /* HANDLER_COMEBACK */ in cgi_recv_response()
599 static handler_t cgi_process_rd_revents(handler_ctx * const hctx, request_st * const r, int revents… in cgi_process_rd_revents() argument
601 handler_t rc = cgi_recv_response(r, hctx); /*(might invalidate hctx)*/ in cgi_process_rd_revents()
607 if (r->resp_body_started) { in cgi_process_rd_revents()
614 const unsigned short flags = r->conf.stream_response_body; in cgi_process_rd_revents()
615 r->conf.stream_response_body &= ~FDEVENT_STREAM_RESPONSE_BUFMIN; in cgi_process_rd_revents()
616 r->conf.stream_response_body |= FDEVENT_STREAM_RESPONSE_POLLRDHUP; in cgi_process_rd_revents()
618 rc = cgi_recv_response(r,hctx); /*(might invalidate hctx)*/ in cgi_process_rd_revents()
620 r->conf.stream_response_body = flags; in cgi_process_rd_revents()
624 r->resp_body_started = 1; in cgi_process_rd_revents()
625 if (0 != http_chunk_append_buffer(r, hctx->response)) { in cgi_process_rd_revents()
629 if (0 == r->http_status) r->http_status = 200; /* OK */ in cgi_process_rd_revents()
670 request_st * const r = hctx->r; in cgi_write_request() local
671 chunkqueue *cq = &r->reqbody_queue; in cgi_write_request()
680 ssize_t wr = chunkqueue_write_chunk_to_pipe(fd, cq, r->conf.errh); in cgi_write_request()
699 log_error(r->conf.errh, __FILE__, __LINE__, in cgi_write_request()
706 log_perror(r->conf.errh, __FILE__, __LINE__, "write() failed"); in cgi_write_request()
714 if (cq->bytes_out == (off_t)r->reqbody_length && !hctx->conf.upgrade) { in cgi_write_request()
718 --r->con->srv->cur_fds; in cgi_write_request()
720 log_perror(r->conf.errh, __FILE__, __LINE__, "cgi stdin close %d failed", fd); in cgi_write_request()
727 if (cq->bytes_in != r->reqbody_length && cqlen < 65536 - 16384) { in cgi_write_request()
729 if (!(r->conf.stream_request_body & FDEVENT_STREAM_REQUEST_POLLIN)) { in cgi_write_request()
730 r->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLIN; in cgi_write_request()
731 r->con->is_readable = 1; /* trigger optimistic read from client */ in cgi_write_request()
753 static int cgi_create_env(request_st * const r, plugin_data * const p, handler_ctx * const hctx, bu… in cgi_create_env() argument
761 log_perror(r->conf.errh, __FILE__, __LINE__, in cgi_create_env()
768 if (0 == r->reqbody_length) { in cgi_create_env()
773 log_perror(r->conf.errh, __FILE__, __LINE__, "open /dev/null"); in cgi_create_env()
777 else if (!(r->conf.stream_request_body /*(if not streaming request body)*/ in cgi_create_env()
780 chunkqueue * const cq = &r->reqbody_queue; in cgi_create_env()
785 && 0 != chunkqueue_open_file_chunk(cq, r->conf.errh)) in cgi_create_env()
791 log_perror(r->conf.errh, __FILE__, __LINE__, in cgi_create_env()
802 if (r->reqbody_length <= 1048576 && r->reqbody_length > 0) in cgi_create_env()
803 bufsz_hint = (unsigned int)r->reqbody_length; in cgi_create_env()
806 log_perror(r->conf.errh, __FILE__, __LINE__, "pipe failed"); in cgi_create_env()
810 if (0 == r->reqbody_length) { in cgi_create_env()
817 log_perror(r->conf.errh, __FILE__, __LINE__, "pipe failed"); in cgi_create_env()
835 if (r->h2_connect_ext) { in cgi_create_env()
837 r->http_version = HTTP_VERSION_1_1; in cgi_create_env()
838 r->http_method = HTTP_METHOD_GET; in cgi_create_env()
841 r->reqbody_length = hctx->orig_reqbody_length; in cgi_create_env()
842 if (r->reqbody_length < 0) in cgi_create_env()
843 r->reqbody_length = 0; in cgi_create_env()
846 http_cgi_headers(r, &opts, cgi_env_add, env); in cgi_create_env()
849 r->reqbody_length = -1; in cgi_create_env()
850 if (r->h2_connect_ext) { in cgi_create_env()
851 r->http_version = HTTP_VERSION_2; in cgi_create_env()
852 r->http_method = HTTP_METHOD_CONNECT; in cgi_create_env()
862 if (!http_header_request_get(r, HTTP_HEADER_OTHER, in cgi_create_env()
902 args[i++] = r->physical.path.ptr; in cgi_create_env()
906 int dfd = fdevent_open_dirname(r->physical.path.ptr,r->conf.follow_symlink); in cgi_create_env()
908 log_perror(r->conf.errh, __FILE__, __LINE__, "open dirname %s failed", r->physical.path.ptr); in cgi_create_env()
911 int serrh_fd = r->conf.serrh ? r->conf.serrh->fd : -1; in cgi_create_env()
924 log_perror(r->conf.errh, __FILE__, __LINE__, "fork failed"); in cgi_create_env()
928 if (0 == r->reqbody_length) { in cgi_create_env()
943 if (0 == r->reqbody_length) { in cgi_create_env()
947 chunkqueue * const cq = &r->reqbody_queue; in cgi_create_env()
953 ++r->con->srv->cur_fds; in cgi_create_env()
966 ++r->con->srv->cur_fds; in cgi_create_env()
971 log_perror(r->conf.errh, __FILE__, __LINE__, "fcntl failed"); in cgi_create_env()
987 if (NULL != r->handler_module) return HANDLER_GO_ON; in URIHANDLER_FUNC()
991 mod_cgi_patch_config(r, p); in URIHANDLER_FUNC()
994 ds = (data_string *)array_match_key_suffix(p->conf.cgi, &r->physical.path); in URIHANDLER_FUNC()
1000 st = r->tmp_sce && buffer_is_equal(&r->tmp_sce->name, &r->physical.path) in URIHANDLER_FUNC()
1001 ? &r->tmp_sce->st in URIHANDLER_FUNC()
1002 : stat_cache_path_stat(&r->physical.path); in URIHANDLER_FUNC()
1009 if (__builtin_expect( (r->h2_connect_ext != 0), 0) && !p->conf.upgrade) { in URIHANDLER_FUNC()
1010 r->http_status = 405; /* Method Not Allowed */ in URIHANDLER_FUNC()
1014 if (r->reqbody_length in URIHANDLER_FUNC()
1016 && !(r->conf.stream_request_body /*(if not streaming request body)*/ in URIHANDLER_FUNC()
1019 r->reqbody_queue.upload_temp_file_size = in URIHANDLER_FUNC()
1025 hctx->ev = r->con->srv->ev; in URIHANDLER_FUNC()
1026 hctx->r = r; in URIHANDLER_FUNC()
1027 hctx->con = r->con; in URIHANDLER_FUNC()
1031 if (__builtin_expect( (r->h2_connect_ext != 0), 0)) { in URIHANDLER_FUNC()
1033 else if (!light_btst(r->rqst_htags, HTTP_HEADER_UPGRADE)) in URIHANDLER_FUNC()
1035 else if (!hctx->conf.upgrade || r->http_version != HTTP_VERSION_1_1) { in URIHANDLER_FUNC()
1037 http_header_request_unset(r, HTTP_HEADER_UPGRADE, in URIHANDLER_FUNC()
1041 hctx->orig_reqbody_length = r->reqbody_length; in URIHANDLER_FUNC()
1042 r->reqbody_length = -1; in URIHANDLER_FUNC()
1045 !(r->conf.stream_response_body /*(if not streaming response body)*/ in URIHANDLER_FUNC()
1048 : (r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN) in URIHANDLER_FUNC()
1059 r->plugin_ctx[p->id] = hctx; in URIHANDLER_FUNC()
1060 r->handler_module = p->self; in URIHANDLER_FUNC()
1073 handler_ctx * const hctx = r->plugin_ctx[p->id]; in SUBREQUEST_FUNC()
1077 (r->conf.stream_request_body & FDEVENT_STREAM_REQUEST_TCP_FIN), 0) in SUBREQUEST_FUNC()
1090 handler_t rc = cgi_process_rd_revents(hctx, r, rd_revents); in SUBREQUEST_FUNC()
1095 handler_t rc = cgi_process_wr_revents(hctx, r, wr_revents); in SUBREQUEST_FUNC()
1099 if ((r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN) in SUBREQUEST_FUNC()
1100 && r->resp_body_started) { in SUBREQUEST_FUNC()
1101 if (chunkqueue_length(&r->write_queue) > 65536 - 4096) { in SUBREQUEST_FUNC()
1105 handler_t rc = cgi_recv_response(r, hctx); /*(might invalidate hctx)*/ in SUBREQUEST_FUNC()
1112 chunkqueue * const cq = &r->reqbody_queue; in SUBREQUEST_FUNC()
1114 if (cq->bytes_in != (off_t)r->reqbody_length) { in SUBREQUEST_FUNC()
1118 && (r->conf.stream_request_body & FDEVENT_STREAM_REQUEST_BUFMIN)){ in SUBREQUEST_FUNC()
1119 r->conf.stream_request_body &= ~FDEVENT_STREAM_REQUEST_POLLIN; in SUBREQUEST_FUNC()
1121 handler_t rc = r->con->reqbody_read(r); in SUBREQUEST_FUNC()
1134 if (-1 == r->reqbody_length && !hctx->conf.upgrade) { in SUBREQUEST_FUNC()
1135 return (r->conf.stream_request_body & FDEVENT_STREAM_REQUEST) in SUBREQUEST_FUNC()
1136 ? http_response_reqbody_read_error(r, 411) in SUBREQUEST_FUNC()
1139 if (cgi_create_env(r, p, hctx, hctx->cgi_handler)) { in SUBREQUEST_FUNC()
1140 r->http_status = 500; in SUBREQUEST_FUNC()
1141 r->handler_module = NULL; in SUBREQUEST_FUNC()
1162 request_st * const r = hctx->r; in cgi_trigger_hctx_timeout() local
1163 joblist_append(r->con); in cgi_trigger_hctx_timeout()
1165 log_error(r->conf.errh, __FILE__, __LINE__, in cgi_trigger_hctx_timeout()
1167 msg, r->physical.path.ptr, (long long)hctx->cgi_pid->pid); in cgi_trigger_hctx_timeout()
1173 handler_t rc = cgi_recv_response(r, hctx); /*(might invalidate hctx)*/ in cgi_trigger_hctx_timeout()
1177 if (0 == r->http_status) r->http_status = 504; /* Gateway Timeout */ in cgi_trigger_hctx_timeout()
1226 log_error_st *errh = hctx ? hctx->r->conf.errh : srv->errh; in cgi_waitpid_cb()
1232 log_error_st *errh = hctx ? hctx->r->conf.errh : srv->errh; in cgi_waitpid_cb()