1919
2020#define _GNU_SOURCE
2121#include <string.h>
22+ #include <stdio.h>
2223
2324#include <fluent-bit/flb_info.h>
2425#include <fluent-bit/flb_kv.h>
@@ -285,27 +286,24 @@ static int http2_data_chunk_recv_callback(nghttp2_session *inner_session,
285286 return -1 ;
286287 }
287288
288- memcpy (stream -> response .body , data , len );
289+ cfl_sds_set_len (stream -> response .body , 0 );
289290
290- cfl_sds_set_len (stream -> response .body , len );
291-
292- stream -> response .body_read_offset = len ;
291+ stream -> response .body_read_offset = 0 ;
293292 }
294- else {
295- resized_buffer = cfl_sds_cat (stream -> response .body ,
296- (const char * ) data ,
297- len );
298293
299- if (resized_buffer == NULL ) {
300- stream -> status = HTTP_STREAM_STATUS_ERROR ;
294+ resized_buffer = cfl_sds_cat (stream -> response .body ,
295+ (const char * ) data ,
296+ len );
301297
302- return -1 ;
303- }
298+ if ( resized_buffer == NULL ) {
299+ stream -> status = HTTP_STREAM_STATUS_ERROR ;
304300
305- stream -> response .body = resized_buffer ;
306- stream -> response .body_read_offset += len ;
301+ return -1 ;
307302 }
308303
304+ stream -> response .body = resized_buffer ;
305+ stream -> response .body_read_offset += len ;
306+
309307 if (stream -> status == HTTP_STREAM_STATUS_RECEIVING_DATA ) {
310308 if (stream -> response .content_length >=
311309 stream -> response .body_read_offset ) {
@@ -387,7 +385,7 @@ static ssize_t http2_data_source_read_callback(nghttp2_session *session,
387385
388386int flb_http2_client_session_init (struct flb_http2_client_session * session )
389387{
390- nghttp2_settings_entry session_settings [1 ];
388+ nghttp2_settings_entry session_settings [3 ];
391389 nghttp2_session_callbacks * callbacks ;
392390 int result ;
393391
@@ -422,10 +420,17 @@ int flb_http2_client_session_init(struct flb_http2_client_session *session)
422420 session_settings [0 ].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS ;
423421 session_settings [0 ].value = 1 ;
424422
423+ session_settings [1 ].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE ;
424+ session_settings [1 ].value = cfl_sds_alloc (session -> parent -> parent -> temporary_buffer );
425+
426+ session_settings [2 ].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH ;
427+ session_settings [2 ].value = 0 ;
428+
429+
425430 result = nghttp2_submit_settings (session -> inner_session ,
426431 NGHTTP2_FLAG_NONE ,
427432 session_settings ,
428- 1 );
433+ 3 );
429434
430435 if (result != 0 ) {
431436 return -3 ;
@@ -480,6 +485,7 @@ int flb_http2_request_begin(struct flb_http_request *request)
480485int flb_http2_request_commit (struct flb_http_request * request )
481486{
482487 struct flb_http_client_session * parent_session ;
488+ cfl_sds_t sds_result ;
483489 struct flb_http2_client_session * session ;
484490 struct flb_http_stream * stream ;
485491 int result ;
@@ -517,10 +523,10 @@ int flb_http2_request_commit(struct flb_http_request *request)
517523 }
518524
519525 if (parent_session -> connection -> tls_session != NULL ) {
520- scheme_as_text = "HTTPS " ;
526+ scheme_as_text = "https " ;
521527 }
522528 else {
523- scheme_as_text = "HTTP " ;
529+ scheme_as_text = "http " ;
524530 }
525531
526532 switch (request -> method ) {
@@ -554,6 +560,22 @@ int flb_http2_request_commit(struct flb_http_request *request)
554560 return -1 ;
555561 }
556562
563+ if (request -> authority == NULL ) {
564+ request -> authority = cfl_sds_create (request -> host );
565+
566+ if (request -> authority == NULL ) {
567+ return -1 ;
568+ }
569+
570+ sds_result = cfl_sds_printf (& request -> authority ,
571+ ":%u" ,
572+ request -> port );
573+
574+ if (sds_result == NULL ) {
575+ return -1 ;
576+ }
577+ }
578+
557579 header_count = request -> headers -> total_count + 7 ;
558580
559581 headers = flb_calloc (header_count , sizeof (nghttp2_nv ));
@@ -580,8 +602,8 @@ int flb_http2_request_commit(struct flb_http_request *request)
580602
581603 headers [header_index ].name = (uint8_t * ) ":authority" ;
582604 headers [header_index ].namelen = strlen (":authority" );
583- headers [header_index ].value = (uint8_t * ) request -> host ;
584- headers [header_index ].valuelen = strlen (request -> host );
605+ headers [header_index ].value = (uint8_t * ) request -> authority ;
606+ headers [header_index ].valuelen = strlen (request -> authority );
585607
586608 header_index ++ ;
587609
0 commit comments