@@ -782,6 +782,11 @@ ngx_http_lua_ffi_req_get_headers_count(ngx_http_request_t *r, int max,
782782{
783783 int count ;
784784 ngx_list_part_t * part ;
785+ #if (NGX_HTTP_V3 )
786+ int has_host = 0 ;
787+ ngx_uint_t i ;
788+ ngx_table_elt_t * header ;
789+ #endif
785790
786791 if (r -> connection -> fd == (ngx_socket_t ) - 1 ) {
787792 return NGX_HTTP_LUA_FFI_BAD_CONTEXT ;
@@ -794,11 +799,54 @@ ngx_http_lua_ffi_req_get_headers_count(ngx_http_request_t *r, int max,
794799 }
795800
796801 part = & r -> headers_in .headers .part ;
802+
803+ #if (NGX_HTTP_V3 )
804+ count = 0 ;
805+ header = part -> elts ;
806+
807+ if (r -> http_version == NGX_HTTP_VERSION_30
808+ && r -> headers_in .server .data != NULL )
809+ {
810+ has_host = 1 ;
811+ count ++ ;
812+ }
813+
814+ if (has_host == 1 ) {
815+ for (i = 0 ; /* void */ ; i ++ ) {
816+ if (i >= part -> nelts ) {
817+ if (part -> next == NULL ) {
818+ break ;
819+ }
820+
821+ part = part -> next ;
822+ header = part -> elts ;
823+ i = 0 ;
824+ }
825+
826+ if (header [i ].key .len == 4
827+ && ngx_strncasecmp (header [i ].key .data ,
828+ (u_char * ) "host" , 4 ) == 0 )
829+ {
830+ continue ;
831+ }
832+
833+ count ++ ;
834+ }
835+
836+ } else {
837+ count = part -> nelts ;
838+ while (part -> next != NULL ) {
839+ part = part -> next ;
840+ count += part -> nelts ;
841+ }
842+ }
843+ #else
797844 count = part -> nelts ;
798845 while (part -> next != NULL ) {
799846 part = part -> next ;
800847 count += part -> nelts ;
801848 }
849+ #endif
802850
803851 if (max > 0 && count > max ) {
804852 * truncated = 1 ;
@@ -821,12 +869,29 @@ ngx_http_lua_ffi_req_get_headers(ngx_http_request_t *r,
821869 ngx_uint_t i ;
822870 ngx_list_part_t * part ;
823871 ngx_table_elt_t * header ;
872+ #if (NGX_HTTP_V3 )
873+ int has_host = 0 ;
874+ #endif
824875
825876 if (count <= 0 ) {
826877 return NGX_OK ;
827878 }
828879
829880 n = 0 ;
881+
882+ #if (NGX_HTTP_V3 )
883+ if (r -> http_version == NGX_HTTP_VERSION_30
884+ && r -> headers_in .server .data != NULL )
885+ {
886+ out [n ].key .data = (u_char * ) "host" ;
887+ out [n ].key .len = sizeof ("host" ) - 1 ;
888+ out [n ].value .len = r -> headers_in .server .len ;
889+ out [n ].value .data = r -> headers_in .server .data ;
890+ has_host = 1 ;
891+ ++ n ;
892+ }
893+ #endif
894+
830895 part = & r -> headers_in .headers .part ;
831896 header = part -> elts ;
832897
@@ -842,6 +907,14 @@ ngx_http_lua_ffi_req_get_headers(ngx_http_request_t *r,
842907 i = 0 ;
843908 }
844909
910+ #if (NGX_HTTP_V3 )
911+ if (has_host == 1 && header [i ].key .len == 4
912+ && ngx_strncasecmp (header [i ].key .data , (u_char * ) "host" , 4 ) == 0 )
913+ {
914+ continue ;
915+ }
916+ #endif
917+
845918 if (raw ) {
846919 out [n ].key .data = header [i ].key .data ;
847920 out [n ].key .len = (int ) header [i ].key .len ;
0 commit comments