@@ -69,6 +69,7 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
69
69
* rb->busy = NULL;
70
70
* rb->chunked = NULL;
71
71
* rb->received = 0;
72
+ * rb->last_saved = 0;
72
73
*/
73
74
74
75
rb -> rest = -1 ;
@@ -941,15 +942,32 @@ ngx_http_request_body_length_filter(ngx_http_request_t *r, ngx_chain_t *in)
941
942
942
943
rb = r -> request_body ;
943
944
945
+ out = NULL ;
946
+ ll = & out ;
947
+
944
948
if (rb -> rest == -1 ) {
945
949
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
946
950
"http request body content length filter" );
947
951
948
952
rb -> rest = r -> headers_in .content_length_n ;
949
- }
950
953
951
- out = NULL ;
952
- ll = & out ;
954
+ if (rb -> rest == 0 ) {
955
+
956
+ tl = ngx_chain_get_free_buf (r -> pool , & rb -> free );
957
+ if (tl == NULL ) {
958
+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
959
+ }
960
+
961
+ b = tl -> buf ;
962
+
963
+ ngx_memzero (b , sizeof (ngx_buf_t ));
964
+
965
+ b -> last_buf = 1 ;
966
+
967
+ * ll = tl ;
968
+ ll = & tl -> next ;
969
+ }
970
+ }
953
971
954
972
for (cl = in ; cl ; cl = cl -> next ) {
955
973
@@ -1013,6 +1031,9 @@ ngx_http_request_body_chunked_filter(ngx_http_request_t *r, ngx_chain_t *in)
1013
1031
1014
1032
rb = r -> request_body ;
1015
1033
1034
+ out = NULL ;
1035
+ ll = & out ;
1036
+
1016
1037
if (rb -> rest == -1 ) {
1017
1038
1018
1039
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
@@ -1029,9 +1050,6 @@ ngx_http_request_body_chunked_filter(ngx_http_request_t *r, ngx_chain_t *in)
1029
1050
rb -> rest = cscf -> large_client_header_buffers .size ;
1030
1051
}
1031
1052
1032
- out = NULL ;
1033
- ll = & out ;
1034
-
1035
1053
for (cl = in ; cl ; cl = cl -> next ) {
1036
1054
1037
1055
b = NULL ;
@@ -1188,15 +1206,16 @@ ngx_int_t
1188
1206
ngx_http_request_body_save_filter (ngx_http_request_t * r , ngx_chain_t * in )
1189
1207
{
1190
1208
ngx_buf_t * b ;
1191
- ngx_chain_t * cl ;
1209
+ ngx_chain_t * cl , * tl , * * ll ;
1192
1210
ngx_http_request_body_t * rb ;
1193
1211
1194
1212
rb = r -> request_body ;
1195
1213
1196
- #if ( NGX_DEBUG )
1214
+ ll = & rb -> bufs ;
1197
1215
1198
- #if 0
1199
1216
for (cl = rb -> bufs ; cl ; cl = cl -> next ) {
1217
+
1218
+ #if 0
1200
1219
ngx_log_debug7 (NGX_LOG_DEBUG_EVENT , r -> connection -> log , 0 ,
1201
1220
"http body old buf t:%d f:%d %p, pos %p, size: %z "
1202
1221
"file: %O, size: %O" ,
@@ -1205,10 +1224,13 @@ ngx_http_request_body_save_filter(ngx_http_request_t *r, ngx_chain_t *in)
1205
1224
cl -> buf -> last - cl -> buf -> pos ,
1206
1225
cl -> buf -> file_pos ,
1207
1226
cl -> buf -> file_last - cl -> buf -> file_pos );
1208
- }
1209
1227
#endif
1210
1228
1229
+ ll = & cl -> next ;
1230
+ }
1231
+
1211
1232
for (cl = in ; cl ; cl = cl -> next ) {
1233
+
1212
1234
ngx_log_debug7 (NGX_LOG_DEBUG_EVENT , r -> connection -> log , 0 ,
1213
1235
"http body new buf t:%d f:%d %p, pos %p, size: %z "
1214
1236
"file: %O, size: %O" ,
@@ -1217,16 +1239,32 @@ ngx_http_request_body_save_filter(ngx_http_request_t *r, ngx_chain_t *in)
1217
1239
cl -> buf -> last - cl -> buf -> pos ,
1218
1240
cl -> buf -> file_pos ,
1219
1241
cl -> buf -> file_last - cl -> buf -> file_pos );
1220
- }
1221
1242
1222
- #endif
1243
+ if ( cl -> buf -> last_buf ) {
1223
1244
1224
- /* TODO: coalesce neighbouring buffers */
1245
+ if (rb -> last_saved ) {
1246
+ ngx_log_error (NGX_LOG_ALERT , r -> connection -> log , 0 ,
1247
+ "duplicate last buf in save filter" );
1248
+ * ll = NULL ;
1249
+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
1250
+ }
1225
1251
1226
- if (ngx_chain_add_copy (r -> pool , & rb -> bufs , in ) != NGX_OK ) {
1227
- return NGX_HTTP_INTERNAL_SERVER_ERROR ;
1252
+ rb -> last_saved = 1 ;
1253
+ }
1254
+
1255
+ tl = ngx_alloc_chain_link (r -> pool );
1256
+ if (tl == NULL ) {
1257
+ * ll = NULL ;
1258
+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
1259
+ }
1260
+
1261
+ tl -> buf = cl -> buf ;
1262
+ * ll = tl ;
1263
+ ll = & tl -> next ;
1228
1264
}
1229
1265
1266
+ * ll = NULL ;
1267
+
1230
1268
if (r -> request_body_no_buffering ) {
1231
1269
return NGX_OK ;
1232
1270
}
0 commit comments