[mod_ajp13,mod_fastcgi] recv_parse smaller funcs

break *_recv_parse() into a pair of slightly smaller funcs
This commit is contained in:
Glenn Strauss 2021-10-22 23:51:34 -04:00
parent c22a56fe3b
commit fe055165d8
2 changed files with 38 additions and 25 deletions

View File

@ -764,32 +764,30 @@ enum {
};
__attribute_cold__
static handler_t
ajp13_recv_parse (request_st * const r, struct http_response_opts_t * const opts, buffer * const b, size_t n)
ajp13_recv_0(const request_st * const r, const handler_ctx * const hctx)
{
handler_ctx * const hctx = (handler_ctx *)opts->pdata;
log_error_st * const errh = r->conf.errh;
int fin = 0;
if (0 == n) {
if (-1 == hctx->request_id) /*(flag request ended)*/
return HANDLER_FINISHED;
if (!(fdevent_fdnode_interest(hctx->fdn) & FDEVENT_IN)
&& !(r->conf.stream_response_body
& FDEVENT_STREAM_RESPONSE_POLLRDHUP))
return HANDLER_GO_ON;
log_error(errh, __FILE__, __LINE__,
log_error(r->conf.errh, __FILE__, __LINE__,
"unexpected end-of-file (perhaps the ajp13 process died):"
"pid: %d socket: %s",
hctx->proc->pid, hctx->proc->connection_name->ptr);
return HANDLER_ERROR;
}
}
/* future: might try to elide copying if buffer contains full packet(s)
* and prior read did not end in a partial packet */
chunkqueue_append_buffer(hctx->rb, b);
static handler_t
ajp13_recv_parse_loop (request_st * const r, handler_ctx * const hctx)
{
log_error_st * const errh = r->conf.errh;
int fin = 0;
do {
uint8_t header[7];
const off_t rblen = chunkqueue_length(hctx->rb);
@ -838,7 +836,7 @@ ajp13_recv_parse (request_st * const r, struct http_response_opts_t * const opts
(r->http_status == 0 || r->http_status == 200)) {
/* authorizer approved request; ignore the content here */
hctx->send_content_body = 0;
opts->authorizer |= /*(save response streaming flags)*/
hctx->opts.authorizer |= /*(save response streaming flags)*/
(r->conf.stream_response_body
& (FDEVENT_STREAM_RESPONSE
|FDEVENT_STREAM_RESPONSE_BUFMIN)) << 1;
@ -947,6 +945,18 @@ ajp13_recv_parse (request_st * const r, struct http_response_opts_t * const opts
}
static handler_t
ajp13_recv_parse (request_st * const r, struct http_response_opts_t * const opts, buffer * const b, size_t n)
{
handler_ctx * const hctx = (handler_ctx *)opts->pdata;
if (0 == n) return ajp13_recv_0(r, hctx);
/* future: might try to elide copying if buffer contains full packet(s)
* and prior read did not end in a partial packet */
chunkqueue_append_buffer(hctx->rb, b);
return ajp13_recv_parse_loop(r, hctx);
}
static handler_t
ajp13_check_extension (request_st * const r, void *p_d)
{

View File

@ -353,11 +353,8 @@ static void fastcgi_get_packet_body(buffer * const b, handler_ctx * const hctx,
buffer_truncate(b, blen + packet->len - packet->padding);
}
static handler_t fcgi_recv_parse(request_st * const r, struct http_response_opts_t *opts, buffer *b, size_t n) {
handler_ctx *hctx = (handler_ctx *)opts->pdata;
int fin = 0;
if (0 == n) {
__attribute_cold__
static handler_t fcgi_recv_0(const request_st * const r, const handler_ctx * const hctx) {
if (-1 == hctx->request_id) return HANDLER_FINISHED; /*(flag request ended)*/
if (!(fdevent_fdnode_interest(hctx->fdn) & FDEVENT_IN)
&& !(r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_POLLRDHUP))
@ -368,17 +365,16 @@ static handler_t fcgi_recv_parse(request_st * const r, struct http_response_opts
hctx->proc->pid, hctx->proc->connection_name->ptr);
return HANDLER_ERROR;
}
chunkqueue_append_buffer(hctx->rb, b);
}
static handler_t fcgi_recv_parse_loop(request_st * const r, handler_ctx * const hctx) {
/*
* parse the fastcgi packets and forward the content to the write-queue
*
*/
while (fin == 0) {
fastcgi_response_packet packet;
fastcgi_response_packet packet;
int fin = 0;
do {
/* check if we have at least one packet */
if (0 != fastcgi_get_packet(hctx, &packet)) {
/* no full packet */
@ -413,7 +409,7 @@ static handler_t fcgi_recv_parse(request_st * const r, struct http_response_opts
(r->http_status == 0 || r->http_status == 200)) {
/* authorizer approved request; ignore the content here */
hctx->send_content_body = 0;
opts->authorizer |= /*(save response streaming flags)*/
hctx->opts.authorizer |= /*(save response streaming flags)*/
(r->conf.stream_response_body
& (FDEVENT_STREAM_RESPONSE
|FDEVENT_STREAM_RESPONSE_BUFMIN)) << 1;
@ -466,11 +462,18 @@ static handler_t fcgi_recv_parse(request_st * const r, struct http_response_opts
chunkqueue_mark_written(hctx->rb, packet.len);
break;
}
}
} while (0 == fin);
return 0 == fin ? HANDLER_GO_ON : HANDLER_FINISHED;
}
static handler_t fcgi_recv_parse(request_st * const r, struct http_response_opts_t *opts, buffer *b, size_t n) {
handler_ctx * const hctx = (handler_ctx *)opts->pdata;
if (0 == n) return fcgi_recv_0(r, hctx);
chunkqueue_append_buffer(hctx->rb, b);
return fcgi_recv_parse_loop(r, hctx);
}
static handler_t fcgi_check_extension(request_st * const r, void *p_d, int uri_path_handler) {
plugin_data *p = p_d;
handler_t rc;