mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 19:22:42 +01:00
0318cadad4
Summary: Fixes T3887. Two issues: - Macros were generating entirely before the render cache, so audio macros worked fine in previews and the first time the cache was populated, but not afterward. - Instead, parse them before the cache but drop them in after the cache. Clean up all the file querying, too. This makes cached remarkup generate the correct audio beahviors. - Safari sends an HTTP request with a "Range" header, and expects a "206 Partial Content" response. If we don't give it one, it sometimes has trouble figuring out how long a piece of audio is (mostly for longer clips? Or mostly for MP3s?). I'm not exactly sure what triggers it. The net effect is that "loop" does not work when Safari gets confused. While looping a short "quack.wav" worked fine, longer MP3s didn't loop. - Supporting "Range" and "206 Partial Content", which is straightforward, fixes this problem. Test Plan: - Viewed a page with lots of different cached audio macros and lots of different uncached preview audio macros, they all rendered correctly and played audio. - Viewed a macro with a long MP3 audio loop in Safari. Verified it looped after it completed. Used Charles to check that the server received and responded to the "Range" header correctly. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3887 Differential Revision: https://secure.phabricator.com/D7166
83 lines
1.9 KiB
PHP
83 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group aphront
|
|
*/
|
|
final class AphrontFileResponse extends AphrontResponse {
|
|
|
|
private $content;
|
|
private $mimeType;
|
|
private $download;
|
|
private $rangeMin;
|
|
private $rangeMax;
|
|
|
|
public function setDownload($download) {
|
|
$download = preg_replace('/[^A-Za-z0-9_.-]/', '_', $download);
|
|
if (!strlen($download)) {
|
|
$download = 'untitled_document.txt';
|
|
}
|
|
$this->download = $download;
|
|
return $this;
|
|
}
|
|
|
|
public function getDownload() {
|
|
return $this->download;
|
|
}
|
|
|
|
public function setMimeType($mime_type) {
|
|
$this->mimeType = $mime_type;
|
|
return $this;
|
|
}
|
|
|
|
public function getMimeType() {
|
|
return $this->mimeType;
|
|
}
|
|
|
|
public function setContent($content) {
|
|
$this->content = $content;
|
|
return $this;
|
|
}
|
|
|
|
public function buildResponseString() {
|
|
if ($this->rangeMin || $this->rangeMax) {
|
|
$length = ($this->rangeMax - $this->rangeMin) + 1;
|
|
return substr($this->content, $this->rangeMin, $length);
|
|
} else {
|
|
return $this->content;
|
|
}
|
|
}
|
|
|
|
public function setRange($min, $max) {
|
|
$this->rangeMin = $min;
|
|
$this->rangeMax = $max;
|
|
return $this;
|
|
}
|
|
|
|
public function getHeaders() {
|
|
$headers = array(
|
|
array('Content-Type', $this->getMimeType()),
|
|
array('Content-Length', strlen($this->buildResponseString())),
|
|
);
|
|
|
|
if ($this->rangeMin || $this->rangeMax) {
|
|
$len = strlen($this->content);
|
|
$min = $this->rangeMin;
|
|
$max = $this->rangeMax;
|
|
$headers[] = array('Content-Range', "bytes {$min}-{$max}/{$len}");
|
|
}
|
|
|
|
if (strlen($this->getDownload())) {
|
|
$headers[] = array('X-Download-Options', 'noopen');
|
|
|
|
$filename = $this->getDownload();
|
|
$headers[] = array(
|
|
'Content-Disposition',
|
|
'attachment; filename='.$filename,
|
|
);
|
|
}
|
|
|
|
$headers = array_merge(parent::getHeaders(), $headers);
|
|
return $headers;
|
|
}
|
|
|
|
}
|