Lines Matching refs:hctx
189 static handler_t fcgi_stdin_append(handler_ctx *hctx) { in fcgi_stdin_append() argument
191 chunkqueue * const req_cq = &hctx->r->reqbody_queue; in fcgi_stdin_append()
194 int request_id = hctx->request_id; in fcgi_stdin_append()
201 if (-1 != hctx->wb_reqlen) { in fcgi_stdin_append()
202 if (hctx->wb_reqlen >= 0) { in fcgi_stdin_append()
203 hctx->wb_reqlen += sizeof(header); in fcgi_stdin_append()
205 hctx->wb_reqlen -= sizeof(header); in fcgi_stdin_append()
210 …(chunkqueue_is_empty(&hctx->wb) || hctx->wb.first->type == MEM_CHUNK) /* else FILE_CHUNK for temp … in fcgi_stdin_append()
211 ? chunkqueue_append_mem(&hctx->wb, (const char *)&header, sizeof(header)) in fcgi_stdin_append()
212 : chunkqueue_append_mem_min(&hctx->wb, (const char *)&header, sizeof(header)); in fcgi_stdin_append()
213 chunkqueue_steal(&hctx->wb, req_cq, weWant); in fcgi_stdin_append()
217 if (hctx->wb.bytes_in == hctx->wb_reqlen) { in fcgi_stdin_append()
223 chunkqueue_append_mem(&hctx->wb, (const char *)&header, sizeof(header)); in fcgi_stdin_append()
224 hctx->wb_reqlen += (int)sizeof(header); in fcgi_stdin_append()
230 static handler_t fcgi_create_env(handler_ctx *hctx) { in fcgi_create_env() argument
235 gw_host *host = hctx->host; in fcgi_create_env()
236 request_st * const r = hctx->r; in fcgi_create_env()
239 (hctx->gw_mode == FCGI_AUTHORIZER), in fcgi_create_env()
245 size_t rsz = (size_t)(r->read_queue.bytes_out - hctx->wb.bytes_in); in fcgi_create_env()
247 buffer * const b = chunkqueue_prepend_buffer_open_sz(&hctx->wb, rsz); in fcgi_create_env()
251 if (hctx->request_id == 0) { in fcgi_create_env()
252 hctx->request_id = 1; /* always use id 1 as we don't use multiplexing */ in fcgi_create_env()
255 "fcgi-request is already in use: %d", hctx->request_id); in fcgi_create_env()
257 request_id = hctx->request_id; in fcgi_create_env()
260 beginRecord.body.roleB0 = hctx->gw_mode; in fcgi_create_env()
274 chunkqueue_remove_finished_chunks(&hctx->wb); in fcgi_create_env()
284 hctx->wb_reqlen = buffer_clen(b); in fcgi_create_env()
285 chunkqueue_prepend_buffer_commit(&hctx->wb); in fcgi_create_env()
291 …hctx->wb_reqlen += r->reqbody_length;/* (eventual) (minimal) total request size, not necessarily i… in fcgi_create_env()
293 hctx->wb_reqlen = -hctx->wb_reqlen; in fcgi_create_env()
295 fcgi_stdin_append(hctx); in fcgi_create_env()
308 static int fastcgi_get_packet(handler_ctx *hctx, fastcgi_response_packet *packet) { in fastcgi_get_packet() argument
310 off_t rblen = chunkqueue_length(hctx->rb); in fastcgi_get_packet()
313 if (hctx->conf.debug && 0 != rblen) { in fastcgi_get_packet()
314 log_error(hctx->r->conf.errh, __FILE__, __LINE__, in fastcgi_get_packet()
322 if (chunkqueue_peek_data(hctx->rb, &ptr, &rd, hctx->r->conf.errh) < 0) in fastcgi_get_packet()
339 chunkqueue_mark_written(hctx->rb, sizeof(FCGI_Header)); in fastcgi_get_packet()
343 static void fastcgi_get_packet_body(buffer * const b, handler_ctx * const hctx, const fastcgi_respo… in fastcgi_get_packet_body() argument
347 if (chunkqueue_read_data(hctx->rb, in fastcgi_get_packet_body()
349 packet->len, hctx->r->conf.errh) < 0) in fastcgi_get_packet_body()
355 static handler_t fcgi_recv_0(const request_st * const r, const handler_ctx * const hctx) { in fcgi_recv_0() argument
356 if (-1 == hctx->request_id) return HANDLER_FINISHED; /*(flag request ended)*/ in fcgi_recv_0()
357 if (!(fdevent_fdnode_interest(hctx->fdn) & FDEVENT_IN) in fcgi_recv_0()
363 hctx->proc->pid, hctx->proc->connection_name->ptr); in fcgi_recv_0()
368 static handler_t fcgi_recv_parse_loop(request_st * const r, handler_ctx * const hctx) { in fcgi_recv_parse_loop() argument
377 if (0 != fastcgi_get_packet(hctx, &packet)) { in fcgi_recv_parse_loop()
389 buffer *hdrs = hctx->response; in fcgi_recv_parse_loop()
394 fastcgi_get_packet_body(hdrs, hctx, &packet); in fcgi_recv_parse_loop()
395 if (HANDLER_GO_ON != http_response_parse_headers(r, &hctx->opts, hdrs)) { in fcgi_recv_parse_loop()
396 hctx->send_content_body = 0; in fcgi_recv_parse_loop()
401 if (!hctx->response) { in fcgi_recv_parse_loop()
402 hctx->response = chunk_buffer_acquire(); in fcgi_recv_parse_loop()
403 buffer_copy_buffer(hctx->response, hdrs); in fcgi_recv_parse_loop()
406 else if (hctx->gw_mode == GW_AUTHORIZER && in fcgi_recv_parse_loop()
409 hctx->send_content_body = 0; in fcgi_recv_parse_loop()
410 hctx->opts.authorizer |= /*(save response streaming flags)*/ in fcgi_recv_parse_loop()
432 } else if (hctx->send_content_body) { in fcgi_recv_parse_loop()
433 if (0 != http_response_transfer_cqlen(r, hctx->rb, (size_t)(packet.len - packet.padding))) { in fcgi_recv_parse_loop()
436 hctx->send_content_body = 0; in fcgi_recv_parse_loop()
439 if (packet.padding) chunkqueue_mark_written(hctx->rb, packet.padding); in fcgi_recv_parse_loop()
441 chunkqueue_mark_written(hctx->rb, packet.len); in fcgi_recv_parse_loop()
448 fastcgi_get_packet_body(tb, hctx, &packet); in fcgi_recv_parse_loop()
454 hctx->request_id = -1; /*(flag request ended)*/ in fcgi_recv_parse_loop()
460 chunkqueue_mark_written(hctx->rb, packet.len); in fcgi_recv_parse_loop()
469 handler_ctx * const hctx = (handler_ctx *)opts->pdata; in fcgi_recv_parse() local
470 if (0 == n) return fcgi_recv_0(r, hctx); in fcgi_recv_parse()
471 chunkqueue_append_buffer(hctx->rb, b); in fcgi_recv_parse()
472 return fcgi_recv_parse_loop(r, hctx); in fcgi_recv_parse()
488 handler_ctx *hctx = r->plugin_ctx[p->id]; in fcgi_check_extension() local
489 hctx->opts.backend = BACKEND_FASTCGI; in fcgi_check_extension()
490 hctx->opts.parse = fcgi_recv_parse; in fcgi_check_extension()
491 hctx->opts.pdata = hctx; /*(skip +255 for potential padding)*/ in fcgi_check_extension()
492 hctx->opts.max_per_read = sizeof(FCGI_Header)+FCGI_MAX_LENGTH+1; in fcgi_check_extension()
493 hctx->stdin_append = fcgi_stdin_append; in fcgi_check_extension()
494 hctx->create_env = fcgi_create_env; in fcgi_check_extension()
495 if (!hctx->rb) { in fcgi_check_extension()
496 hctx->rb = chunkqueue_init(NULL); in fcgi_check_extension()
499 chunkqueue_reset(hctx->rb); in fcgi_check_extension()