@@ -349,6 +349,8 @@ static int handle_http2_static_resource(
349
349
goto out ;
350
350
}
351
351
352
+ client -> headers_sent = true;
353
+
352
354
ret = send_data_frame (client , content_200 , content_len ,
353
355
frame -> stream_identifier ,
354
356
HTTP2_FLAG_END_STREAM );
@@ -357,6 +359,8 @@ static int handle_http2_static_resource(
357
359
goto out ;
358
360
}
359
361
362
+ client -> end_stream_sent = true;
363
+
360
364
out :
361
365
return ret ;
362
366
}
@@ -375,6 +379,8 @@ static int dynamic_get_req_v2(struct http_resource_detail_dynamic *dynamic_detai
375
379
return ret ;
376
380
}
377
381
382
+ client -> headers_sent = true;
383
+
378
384
remaining = strlen (& client -> url_buffer [dynamic_detail -> common .path_len ]);
379
385
380
386
/* Pass URL to the client */
@@ -422,6 +428,8 @@ static int dynamic_get_req_v2(struct http_resource_detail_dynamic *dynamic_detai
422
428
LOG_DBG ("Cannot send last frame (%d)" , ret );
423
429
}
424
430
431
+ client -> end_stream_sent = true;
432
+
425
433
dynamic_detail -> holder = NULL ;
426
434
427
435
break ;
@@ -491,6 +499,7 @@ static int dynamic_post_req_v2(struct http_resource_detail_dynamic *dynamic_deta
491
499
if (frame -> length == 0 &&
492
500
is_header_flag_set (frame -> flags , HTTP2_FLAG_END_STREAM )) {
493
501
flags = HTTP2_FLAG_END_STREAM ;
502
+ client -> end_stream_sent = true;
494
503
}
495
504
496
505
ret = send_data_frame (client ,
@@ -523,6 +532,7 @@ static int dynamic_post_req_v2(struct http_resource_detail_dynamic *dynamic_deta
523
532
}
524
533
525
534
client -> headers_sent = true;
535
+ client -> end_stream_sent = true;
526
536
}
527
537
528
538
dynamic_detail -> holder = NULL ;
@@ -1102,6 +1112,75 @@ static int handle_incomplete_http_header(struct http_client_ctx *client)
1102
1112
return enter_http_frame_continuation_state (client );
1103
1113
}
1104
1114
1115
+ static int handle_http_frame_headers_end_stream (struct http_client_ctx * client )
1116
+ {
1117
+ struct http2_frame * frame = & client -> current_frame ;
1118
+ int ret = 0 ;
1119
+
1120
+ if (client -> current_detail == NULL ) {
1121
+ goto out ;
1122
+ }
1123
+
1124
+ if (client -> current_detail -> type == HTTP_RESOURCE_TYPE_DYNAMIC ) {
1125
+ struct http_resource_detail_dynamic * dynamic_detail =
1126
+ (struct http_resource_detail_dynamic * )client -> current_detail ;
1127
+ int send_len ;
1128
+
1129
+ send_len = dynamic_detail -> cb (client , HTTP_SERVER_DATA_FINAL ,
1130
+ dynamic_detail -> data_buffer , 0 ,
1131
+ dynamic_detail -> user_data );
1132
+ if (send_len > 0 ) {
1133
+ if (!client -> headers_sent ) {
1134
+ ret = send_headers_frame (
1135
+ client , HTTP_200_OK , frame -> stream_identifier ,
1136
+ client -> current_detail , 0 );
1137
+ if (ret < 0 ) {
1138
+ LOG_DBG ("Cannot write to socket (%d)" , ret );
1139
+ goto out ;
1140
+ }
1141
+
1142
+ client -> headers_sent = true;
1143
+ }
1144
+
1145
+ ret = send_data_frame (client ,
1146
+ dynamic_detail -> data_buffer ,
1147
+ send_len , frame -> stream_identifier ,
1148
+ HTTP2_FLAG_END_STREAM );
1149
+ if (ret < 0 ) {
1150
+ LOG_DBG ("Cannot send data frame (%d)" , ret );
1151
+ goto out ;
1152
+ }
1153
+
1154
+ client -> end_stream_sent = true;
1155
+ }
1156
+
1157
+ dynamic_detail -> holder = NULL ;
1158
+ }
1159
+
1160
+ if (!client -> headers_sent ) {
1161
+ ret = send_headers_frame (
1162
+ client , HTTP_200_OK , frame -> stream_identifier ,
1163
+ client -> current_detail , HTTP2_FLAG_END_STREAM );
1164
+ if (ret < 0 ) {
1165
+ LOG_DBG ("Cannot write to socket (%d)" , ret );
1166
+ goto out ;
1167
+ }
1168
+ } else if (!client -> end_stream_sent ) {
1169
+ ret = send_data_frame (client , NULL , 0 , frame -> stream_identifier ,
1170
+ HTTP2_FLAG_END_STREAM );
1171
+ if (ret < 0 ) {
1172
+ LOG_DBG ("Cannot send last frame (%d)" , ret );
1173
+ }
1174
+ }
1175
+
1176
+ client -> current_detail = NULL ;
1177
+
1178
+ out :
1179
+ release_http_stream_context (client , frame -> stream_identifier );
1180
+
1181
+ return ret ;
1182
+ }
1183
+
1105
1184
int handle_http_frame_headers (struct http_client_ctx * client )
1106
1185
{
1107
1186
struct http2_frame * frame = & client -> current_frame ;
@@ -1191,7 +1270,10 @@ int handle_http_frame_headers(struct http_client_ctx *client)
1191
1270
}
1192
1271
1193
1272
if (is_header_flag_set (frame -> flags , HTTP2_FLAG_END_STREAM )) {
1194
- release_http_stream_context (client , frame -> stream_identifier );
1273
+ ret = handle_http_frame_headers_end_stream (client );
1274
+ if (ret < 0 ) {
1275
+ return ret ;
1276
+ }
1195
1277
}
1196
1278
1197
1279
if (frame -> padding_len > 0 ) {
0 commit comments