Changeset 29968 for trunk/src/wp-includes/class-http.php
- Timestamp:
- 10/20/2014 07:31:45 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-http.php
r29864 r29968 209 209 * and pick its name using the basename of the $url. 210 210 */ 211 if ( $r['stream'] && empty( $r['filename'] ) ) 212 $r['filename'] = get_temp_dir() . basename( $url ); 211 if ( $r['stream'] && empty( $r['filename'] ) ) { 212 $r['filename'] = wp_unique_filename( get_temp_dir(), basename( $url ) ); 213 } 213 214 214 215 /* … … 1097 1098 $this_block_size = strlen( $block ); 1098 1099 1099 if ( isset( $r['limit_response_size'] ) && ( $bytes_written + $this_block_size ) > $r['limit_response_size'] ) 1100 $block = substr( $block, 0, ( $r['limit_response_size'] - $bytes_written ) ); 1100 if ( isset( $r['limit_response_size'] ) && ( $bytes_written + $this_block_size ) > $r['limit_response_size'] ) { 1101 $this_block_size = ( $r['limit_response_size'] - $bytes_written ); 1102 $block = substr( $block, 0, $this_block_size ); 1103 } 1101 1104 1102 1105 $bytes_written_to_file = fwrite( $stream_handle, $block ); … … 1324 1327 */ 1325 1328 private $stream_handle = false; 1329 1330 /** 1331 * The total bytes written in the current request. 1332 * 1333 * @since 4.1.0 1334 * @access prviate 1335 * @var int 1336 */ 1337 private $bytes_written_total = 0; 1326 1338 1327 1339 /** … … 1497 1509 $theHeaders = WP_Http::processHeaders( $this->headers, $url ); 1498 1510 $theBody = $this->body; 1511 $bytes_written_total = $this->bytes_written_total; 1499 1512 1500 1513 $this->headers = ''; 1501 1514 $this->body = ''; 1515 $this->bytes_written_total = 0; 1502 1516 1503 1517 $curl_error = curl_errno( $handle ); … … 1505 1519 // If an error occurred, or, no response. 1506 1520 if ( $curl_error || ( 0 == strlen( $theBody ) && empty( $theHeaders['headers'] ) ) ) { 1507 if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error && $r['stream'] ) { 1508 fclose( $this->stream_handle ); 1509 return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) ); 1510 } 1511 if ( $curl_error = curl_error( $handle ) ) { 1512 curl_close( $handle ); 1513 return new WP_Error( 'http_request_failed', $curl_error ); 1521 if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error && $r['stream'] ) { 1522 if ( ! $this->max_body_length || $this->max_body_length != $bytes_written_total ) { 1523 fclose( $this->stream_handle ); 1524 return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) ); 1525 } 1526 } else { 1527 if ( $curl_error = curl_error( $handle ) ) { 1528 curl_close( $handle ); 1529 return new WP_Error( 'http_request_failed', $curl_error ); 1530 } 1514 1531 } 1515 1532 if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) { … … 1562 1579 * 1563 1580 * The contents of the document are passed in chunks, so we append to the $body property for temporary storage. 1564 * Returning a length shorter than the length of $data passed in will cause cURL to abort the request as "completed"1581 * Returning a length shorter than the length of $data passed in will cause cURL to abort the request with CURLE_WRITE_ERROR 1565 1582 * 1566 1583 * @since 3.6.0 … … 1571 1588 $data_length = strlen( $data ); 1572 1589 1573 if ( $this->max_body_length && ( strlen( $this->body ) + $data_length ) > $this->max_body_length ) 1574 $data = substr( $data, 0, ( $this->max_body_length - $data_length ) ); 1590 if ( $this->max_body_length && ( $this->bytes_written_total + $data_length ) > $this->max_body_length ) { 1591 $data_length = ( $this->max_body_length - $this->bytes_written_total ); 1592 $data = substr( $data, 0, $data_length ); 1593 } 1575 1594 1576 1595 if ( $this->stream_handle ) { … … 1580 1599 $bytes_written = $data_length; 1581 1600 } 1601 1602 $this->bytes_written_total += $bytes_written; 1582 1603 1583 1604 // Upon event of this function returning less than strlen( $data ) curl will error with CURLE_WRITE_ERROR.
Note: See TracChangeset
for help on using the changeset viewer.