summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-03 11:03:39 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-03 11:03:39 -0400
commit46379956b305037df7599985ecc29ae9006d2b7b (patch)
treecc4870e193ee28b152773eb8e316b0fcdf701ab7 /src
parentb172367ec9416268871cef70d2433462fb7f8868 (diff)
downloadzipstream-php-46379956b305037df7599985ecc29ae9006d2b7b.tar.bz2
zipstream-php-46379956b305037df7599985ecc29ae9006d2b7b.zip
add HTTPResponseWriter#get_headers()
Diffstat (limited to 'src')
-rw-r--r--src/ZipStream.php35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/ZipStream.php b/src/ZipStream.php
index 8648b9f..3f2d480 100644
--- a/src/ZipStream.php
+++ b/src/ZipStream.php
@@ -201,11 +201,13 @@ final class HTTPResponseWriter implements Writer {
/**
* Flush metadata and begin streaming archive contents.
*
- * @todo
* @return void
*/
public function open() : void {
- # TODO: send http headers
+ # write response headers
+ foreach ($this->get_headers as $key => $val) {
+ header("$key: $val");
+ }
}
/**
@@ -227,6 +229,35 @@ final class HTTPResponseWriter implements Writer {
public function close() : void {
# ignore
}
+
+ /**
+ * Get HTTP headers.
+ *
+ * @internal
+ *
+ * @return array Hash of HTTP headers.
+ */
+ private function get_headers() : array {
+ # build pre-RFC6266 file name
+ $old_name = preg_replace('/[^a-z0-9_.-]+/', '_', $this->args['name']);
+
+ # build URI-encoded (RFC6266) file name
+ $new_name = urlencode($this->args['name']);
+
+ # build and return response headers
+ return [
+ 'Content-Type' => $this->args['type'],
+ 'Content-Disposition' => join('; ', [
+ 'attachment',
+ "filename=\"{$old_name}\"",
+ "filename*=UTF-8''{$new_name}"
+ ]),
+
+ 'Pragma' => 'public',
+ 'Cache-Control' => 'public, must-revalidate',
+ 'Content-Transfer-Encoding' => 'binary',
+ ];
+ }
};
/**