fastcgi: Fix fastcgi_dump()
This commit is contained in:
@@ -416,8 +416,17 @@ int fastcgi_header(fastcgi_cnx_t *cnx, http_res *res, char *err_msg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fastcgi_dump(fastcgi_cnx_t *cnx, char *buf, long len) {
|
||||
return sock_recv_x(&cnx->socket, buf, len, 0) == -1 ? -1 : 0;
|
||||
int fastcgi_dump(fastcgi_cnx_t *cnx, char *buf, const long len) {
|
||||
for (long ret, rcv = 0; rcv < len; rcv += ret) {
|
||||
if ((ret = sock_recv_chunk_header(&cnx->out)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
const long min = ret > len - rcv ? len - rcv : ret;
|
||||
if ((ret = sock_recv_x(&cnx->out, buf + rcv, min, 0)) <= 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fastcgi_receive(fastcgi_cnx_t *cnx, sock *client, unsigned long len) {
|
||||
|
||||
@@ -145,16 +145,17 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t **fcgi_cnx) {
|
||||
content_type != NULL &&
|
||||
strstarts(content_type, "text/html") &&
|
||||
ctx->content_length != -1 &&
|
||||
ctx->content_length <= sizeof(ctx->msg_content) - 1)
|
||||
ctx->content_length < sizeof(ctx->msg_content))
|
||||
{
|
||||
fastcgi_dump(*fcgi_cnx, ctx->msg_content, sizeof(ctx->msg_content));
|
||||
fastcgi_dump(*fcgi_cnx, ctx->msg_content, ctx->content_length);
|
||||
ctx->msg_content[ctx->content_length] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ctx->use_fastcgi = 1;
|
||||
ctx->content_length = -1;
|
||||
|
||||
if (http_get_header_field(&res->hdr, "Content-Length") == NULL) {
|
||||
if (content_length_f == NULL) {
|
||||
http_add_header_field(&res->hdr, "Transfer-Encoding", "chunked");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user