@@ -160,6 +160,9 @@ fh_http1_res_ctx_create (pool_t *pool)
160160 ctx -> iov_size = 0 ;
161161 ctx -> iov_data_size = 0 ;
162162 ctx -> state = FH_RES_STATE_HEADERS ;
163+ ctx -> response -> protocol = FH_PROTOCOL_HTTP_1_1 ;
164+ ctx -> response -> encoding = FH_ENCODING_PLAIN ;
165+ ctx -> response -> no_send_body = false;
163166 ctx -> response -> headers = NULL ;
164167 ctx -> response -> content_length = 0 ;
165168 ctx -> response -> pool = pool ;
@@ -289,6 +292,7 @@ fh_use_default_error_response (struct fh_http1_res_ctx *ctx,
289292 default_error_response_buf .attrs .mem .data = (uint8_t * ) data ;
290293 default_error_response_buf .attrs .mem .len = buf_len ;
291294 default_error_response_buf .attrs .mem .cap = buf_len ;
295+ response -> encoding = FH_ENCODING_PLAIN ;
292296 response -> content_length = buf_len ;
293297
294298 return true;
@@ -302,7 +306,7 @@ fh_res_send_headers (struct fh_http1_res_ctx *ctx, struct fh_conn *conn)
302306 struct fh_response * response = ctx -> response ;
303307 struct fh_headers * headers = response -> headers ;
304308 const bool set_transfer_encoding = response -> encoding != FH_ENCODING_PLAIN ;
305- const size_t generated_header_count = 1 + ( set_transfer_encoding ? 1 : 0 ) ;
309+ const size_t generated_header_count = 1 ;
306310 const size_t header_count = (headers ? headers -> count : 0 )
307311 + default_header_count + generated_header_count ;
308312 size_t status_text_len = 0 ;
@@ -368,7 +372,9 @@ fh_res_send_body (struct fh_http1_res_ctx *ctx, struct fh_conn *conn)
368372 fd_t sockfd = conn -> client_sockfd ;
369373 struct fh_response * response = ctx -> response ;
370374
371- if ((!response -> use_default_error_response && !response -> content_length ) || response -> no_send_body )
375+ if ((!response -> use_default_error_response && !response -> content_length
376+ && response -> encoding != FH_ENCODING_CHUNKED )
377+ || response -> no_send_body )
372378 return H1_RES_DONE ;
373379
374380 struct fh_link * link = response -> use_default_error_response
@@ -458,7 +464,9 @@ fh_res_send_body (struct fh_http1_res_ctx *ctx, struct fh_conn *conn)
458464 struct fh_buf * buf = response -> body_start -> buf ;
459465
460466 buf -> attrs .mem .len -= size ;
461- buf -> attrs .mem .data = (void * ) (((char * ) buf -> attrs .mem .data ) + size );
467+ buf -> attrs .mem .data
468+ = (void * ) (((char * ) buf -> attrs .mem .data )
469+ + size );
462470 iov -> iov_len = buf -> attrs .mem .len ;
463471 iov -> iov_base = buf -> attrs .mem .data ;
464472 }
@@ -491,9 +499,9 @@ fh_res_send_body (struct fh_http1_res_ctx *ctx, struct fh_conn *conn)
491499
492500 fh_pr_debug ("Sending fd #%d" , in_fd );
493501
494- ssize_t sent
495- = sendfile64 ( sockfd , in_fd , (off64_t * ) & buf -> attrs .file .file_off ,
496- buf -> attrs .file .file_len );
502+ ssize_t sent = sendfile64 (
503+ sockfd , in_fd , (off64_t * ) & buf -> attrs .file .file_off ,
504+ buf -> attrs .file .file_len );
497505
498506 if (sent < 1 || ((size_t ) sent ) < buf -> attrs .file .file_len )
499507 {
@@ -550,6 +558,8 @@ fh_res_write_data (struct fh_http1_res_ctx *ctx, struct fh_conn *conn)
550558
551559 for (;;)
552560 {
561+ fh_pr_debug ("ctx->iov_size: %zu" , ctx -> iov_size );
562+
553563 ssize_t wrote = writev (sockfd , ctx -> iov , ctx -> iov_size );
554564
555565 if (wrote < 1 )
0 commit comments