Browse Source

[mod_fastcgi] decode Transfer-Encoding: chunked

decode Transfer-Encoding: chunked from mod_fastcgi backend
master
Glenn Strauss 1 year ago
parent
commit
9ca668c870
  1. 27
      src/mod_fastcgi.c

27
src/mod_fastcgi.c

@ -397,6 +397,31 @@ static void fastcgi_get_packet_body(buffer *b, handler_ctx *hctx, fastcgi_respon
chunkqueue_mark_written(hctx->rb, packet->len);
}
static int
mod_fastcgi_chunk_decode_transfer_cqlen (request_st * const r, chunkqueue * const src, const unsigned int len)
{
if (!r->resp_decode_chunked)
return http_chunk_transfer_cqlen(r, src, len);
if (0 == len) return 0;
/* specialized for mod_fastcgi to decode chunked encoding;
* FastCGI packet data is all type MEM_CHUNK
* entire src cq is processed, minus packet.padding at end
* (This extra work can be avoided if FastCGI backend does not send
* Transfer-Encoding: chunked, which FastCGI is not supposed to do) */
uint32_t remain = len, wr;
for (const chunk *c = src->first; c && remain; c = c->next, remain -= wr) {
/*assert(c->type == MEM_CHUNK);*/
wr = buffer_string_length(c->mem) - c->offset;
if (wr > remain) wr = remain;
if (0 != http_chunk_decode_append_mem(r, c->mem->ptr+c->offset, wr))
return -1;
}
chunkqueue_mark_written(src, len);
return 0;
}
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;
@ -459,7 +484,7 @@ static handler_t fcgi_recv_parse(request_st * const r, struct http_response_opts
hctx->send_content_body = 0;
}
} else if (hctx->send_content_body) {
if (0 != http_chunk_transfer_cqlen(r, hctx->rb, packet.len - packet.padding)) {
if (0 != mod_fastcgi_chunk_decode_transfer_cqlen(r, hctx->rb, packet.len - packet.padding)) {
/* error writing to tempfile;
* truncate response or send 500 if nothing sent yet */
fin = 1;

Loading…
Cancel
Save