@@ -180,10 +180,6 @@ SAPI_API void sapi_handle_post(void *arg TSRMLS_DC)
180
180
{
181
181
if (SG (request_info ).post_entry && SG (request_info ).content_type_dup ) {
182
182
SG (request_info ).post_entry -> post_handler (SG (request_info ).content_type_dup , arg TSRMLS_CC );
183
- /*if (SG(request_info).request_body) {
184
- php_stream_close(SG(request_info).request_body);
185
- SG(request_info).request_body = NULL;
186
- }*/
187
183
efree (SG (request_info ).content_type_dup );
188
184
SG (request_info ).content_type_dup = NULL ;
189
185
}
@@ -249,43 +245,61 @@ static void sapi_read_post_data(TSRMLS_D)
249
245
}
250
246
}
251
247
252
-
253
- SAPI_API SAPI_POST_READER_FUNC (sapi_read_standard_form_data )
248
+ SAPI_API int sapi_read_post_block (char * buffer , size_t buflen TSRMLS_DC )
254
249
{
255
250
int read_bytes ;
256
251
252
+ if (!sapi_module .read_post ) {
253
+ return -1 ;
254
+ }
255
+
256
+ read_bytes = sapi_module .read_post (buffer , buflen TSRMLS_CC );
257
+
258
+ if (read_bytes > 0 ) {
259
+ /* gogo */
260
+ SG (read_post_bytes ) += read_bytes ;
261
+ }
262
+ if (read_bytes < buflen ) {
263
+ /* done */
264
+ SG (post_read ) = 1 ;
265
+ }
266
+
267
+ return read_bytes ;
268
+ }
269
+
270
+ SAPI_API SAPI_POST_READER_FUNC (sapi_read_standard_form_data )
271
+ {
257
272
if ((SG (post_max_size ) > 0 ) && (SG (request_info ).content_length > SG (post_max_size ))) {
258
273
php_error_docref (NULL TSRMLS_CC , E_WARNING , "POST Content-Length of %ld bytes exceeds the limit of %ld bytes" ,
259
274
SG (request_info ).content_length , SG (post_max_size ));
260
275
return ;
261
276
}
277
+
262
278
SG (request_info ).request_body = php_stream_temp_create (TEMP_STREAM_DEFAULT , SAPI_POST_BLOCK_SIZE );
263
279
264
280
if (sapi_module .read_post ) {
281
+ int read_bytes ;
282
+
265
283
for (;;) {
266
284
char buffer [SAPI_POST_BLOCK_SIZE ];
267
285
268
- read_bytes = sapi_module . read_post (buffer , SAPI_POST_BLOCK_SIZE TSRMLS_CC );
269
- if ( read_bytes <= 0 ) {
270
- /* failure */
271
- break ;
286
+ read_bytes = sapi_read_post_block (buffer , SAPI_POST_BLOCK_SIZE TSRMLS_CC );
287
+
288
+ if ( read_bytes > 0 ) {
289
+ php_stream_write ( SG ( request_info ). request_body , buffer , read_bytes ) ;
272
290
}
273
- SG (read_post_bytes ) += read_bytes ;
274
291
275
292
if ((SG (post_max_size ) > 0 ) && (SG (read_post_bytes ) > SG (post_max_size ))) {
276
293
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Actual POST length does not match Content-Length, and exceeds %ld bytes" , SG (post_max_size ));
277
294
break ;
278
295
}
279
296
280
- php_stream_write (SG (request_info ).request_body , buffer , read_bytes );
281
-
282
297
if (read_bytes < SAPI_POST_BLOCK_SIZE ) {
283
298
/* done */
284
299
break ;
285
300
}
286
301
}
287
-
288
- php_stream_rewind (SG (request_info ).request_body );
302
+ php_stream_rewind (SG (request_info ).request_body );
289
303
}
290
304
}
291
305
@@ -455,21 +469,13 @@ SAPI_API void sapi_activate(TSRMLS_D)
455
469
456
470
/* Handle request method */
457
471
if (SG (server_context )) {
458
- if (SG (request_info ).request_method ) {
459
- if (PG (enable_post_data_reading )
460
- && SG (request_info ).content_type
461
- && !strcmp (SG (request_info ).request_method , "POST" )) {
462
- /* HTTP POST may contain form data to be processed into variables
463
- * depending on given content type */
464
- sapi_read_post_data (TSRMLS_C );
465
- } else {
466
- /* Any other method with content payload will fill php://input stream.
467
- * It's up to the webserver to decide whether to allow a method or not. */
468
- SG (request_info ).content_type_dup = NULL ;
469
- if (sapi_module .default_post_reader ) {
470
- sapi_module .default_post_reader (TSRMLS_C );
471
- }
472
- }
472
+ if (PG (enable_post_data_reading )
473
+ && SG (request_info ).content_type
474
+ && SG (request_info ).request_method
475
+ && !strcmp (SG (request_info ).request_method , "POST" )) {
476
+ /* HTTP POST may contain form data to be processed into variables
477
+ * depending on given content type */
478
+ sapi_read_post_data (TSRMLS_C );
473
479
} else {
474
480
SG (request_info ).content_type_dup = NULL ;
475
481
}
@@ -500,15 +506,15 @@ SAPI_API void sapi_deactivate(TSRMLS_D)
500
506
zend_llist_destroy (& SG (sapi_headers ).headers );
501
507
if (SG (request_info ).request_body ) {
502
508
SG (request_info ).request_body = NULL ;
503
- } else if (SG (server_context )) {
504
- if ( sapi_module . read_post ) {
509
+ } else if (SG (server_context )) {
510
+ if (! SG ( post_read )) {
505
511
/* make sure we've consumed all request input data */
506
512
char dummy [SAPI_POST_BLOCK_SIZE ];
507
513
int read_bytes ;
508
514
509
- while (( read_bytes = sapi_module . read_post ( dummy , sizeof ( dummy ) - 1 TSRMLS_CC )) > 0 ) {
510
- SG ( read_post_bytes ) += read_bytes ;
511
- }
515
+ do {
516
+ read_bytes = sapi_read_post_block ( dummy , SAPI_POST_BLOCK_SIZE TSRMLS_CC ) ;
517
+ } while ( SAPI_POST_BLOCK_SIZE == read_bytes );
512
518
}
513
519
}
514
520
if (SG (request_info ).auth_user ) {
0 commit comments