Commit 9a14ebcd authored by mikeytown2's avatar mikeytown2

Issue #1874600 by mikeytown2: Reassemble byterange responses.

parent 98349311
......@@ -1984,6 +1984,44 @@ function httprl_decode_data(&$result) {
$result->data = gzinflate($result->data);
}
}
// Reassemble multipart/byteranges response.
if (isset($result->headers['content-type']) && strpos($result->headers['content-type'], 'multipart/byteranges; boundary=') !== FALSE) {
// Get boundary string.
$boundary = "\r\n--" . substr($result->headers['content-type'], 31);
$datas = explode($boundary, $result->data);
$result->data = '';
foreach ($datas as $data) {
$split = preg_split("/\r\n\r\n|\n\n|\r\r/", $data, 2);
if (count($split) < 2) {
continue;
}
// Separate the data from the headers.
list($response, $data) = $split;
$response = array_filter(preg_split("/\r\n|\n|\r/", $response));
// Parse the response headers.
while ($line = trim(array_shift($response))) {
list($name, $value) = explode(':', $line, 2);
$name = strtolower($name);
// Add key value pairs to the header.
if ($name != 'content-range') {
$result->headers[$name] = trim($value);
}
}
$result->data .= $data;
}
}
// Fix content-length for fake 206.
if ( !empty($result->options['max_data_size'])
&& !is_null($result->options['max_data_size'])
&& isset($result->headers['content-length'])
) {
$result->headers['content-length'] = httprl_strlen($result->data);
}
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment