@@ -39,12 +39,12 @@ public function emit(ResponseInterface $response) : bool
3939
4040 $ range = $ this ->parseContentRange ($ response ->getHeaderLine ('Content-Range ' ));
4141
42- if (is_array ( $ range ) && $ range[ 0 ] === 'bytes ' ) {
43- $ this ->emitBodyRange ( $ range , $ response );
42+ if (null === $ range || 'bytes ' !== $ range [ 0 ] ) {
43+ $ this ->emitBody ( $ response );
4444 return true ;
4545 }
4646
47- $ this ->emitBody ( $ response );
47+ $ this ->emitBodyRange ( $ range , $ response );
4848 return true ;
4949 }
5050
@@ -93,7 +93,7 @@ private function emitBodyRange(array $range, ResponseInterface $response) : void
9393
9494 $ remaining = $ length ;
9595
96- while ($ remaining >= $ maxBufferLength && ! $ body ->eof ()) {
96+ while ($ remaining >= $ this -> maxBufferLength && ! $ body ->eof ()) {
9797 $ contents = $ body ->read ($ this ->maxBufferLength );
9898 $ remaining -= strlen ($ contents );
9999
@@ -109,19 +109,20 @@ private function emitBodyRange(array $range, ResponseInterface $response) : void
109109 * Parse content-range header
110110 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
111111 *
112- * @return false |array [unit, first, last, length]; returns false if no
112+ * @return null |array [unit, first, last, length]; returns null if no
113113 * content range or an invalid content range is provided
114114 */
115- private function parseContentRange (string $ header )
115+ private function parseContentRange (string $ header ) : ? array
116116 {
117- if (preg_match ('/(?P<unit>[\w]+)\s+(?P<first>\d+)-(?P<last>\d+)\/(?P<length>\d+|\*)/ ' , $ header , $ matches )) {
118- return [
119- $ matches ['unit ' ],
120- (int ) $ matches ['first ' ],
121- (int ) $ matches ['last ' ],
122- $ matches ['length ' ] === '* ' ? '* ' : (int ) $ matches ['length ' ],
123- ];
117+ if (! preg_match ('/(?P<unit>[\w]+)\s+(?P<first>\d+)-(?P<last>\d+)\/(?P<length>\d+|\*)/ ' , $ header , $ matches )) {
118+ return null ;
124119 }
125- return false ;
120+
121+ return [
122+ $ matches ['unit ' ],
123+ (int ) $ matches ['first ' ],
124+ (int ) $ matches ['last ' ],
125+ $ matches ['length ' ] === '* ' ? '* ' : (int ) $ matches ['length ' ],
126+ ];
126127 }
127128}
0 commit comments