response.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Frank Karlitschek <frank@owncloud.org>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @copyright Copyright (c) 2015, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. /**
  27. * Public interface of ownCloud for apps to use.
  28. * Response Class.
  29. *
  30. */
  31. // use OCP namespace for all classes that are considered public.
  32. // This means that they should be used by apps instead of the internal ownCloud classes
  33. namespace OCP;
  34. /**
  35. * This class provides convenient functions to send the correct http response headers
  36. */
  37. class Response {
  38. /**
  39. * Enable response caching by sending correct HTTP headers
  40. * @param int $cache_time time to cache the response
  41. * >0 cache time in seconds
  42. * 0 and <0 enable default browser caching
  43. * null cache indefinitly
  44. */
  45. static public function enableCaching( $cache_time = null ) {
  46. \OC_Response::enableCaching( $cache_time );
  47. }
  48. /**
  49. * Checks and set Last-Modified header, when the request matches sends a
  50. * 'not modified' response
  51. * @param string $lastModified time when the reponse was last modified
  52. */
  53. static public function setLastModifiedHeader( $lastModified ) {
  54. \OC_Response::setLastModifiedHeader( $lastModified );
  55. }
  56. /**
  57. * Sets the content disposition header (with possible workarounds)
  58. * @param string $filename file name
  59. * @param string $type disposition type, either 'attachment' or 'inline'
  60. */
  61. static public function setContentDispositionHeader( $filename, $type = 'attachment' ) {
  62. \OC_Response::setContentDispositionHeader( $filename, $type );
  63. }
  64. /**
  65. * Sets the content length header (with possible workarounds)
  66. * @param string|int|float $length Length to be sent
  67. */
  68. static public function setContentLengthHeader($length) {
  69. \OC_Response::setContentLengthHeader($length);
  70. }
  71. /**
  72. * Disable browser caching
  73. * @see enableCaching with cache_time = 0
  74. */
  75. static public function disableCaching() {
  76. \OC_Response::disableCaching();
  77. }
  78. /**
  79. * Checks and set ETag header, when the request matches sends a
  80. * 'not modified' response
  81. * @param string $etag token to use for modification check
  82. */
  83. static public function setETagHeader( $etag ) {
  84. \OC_Response::setETagHeader( $etag );
  85. }
  86. /**
  87. * Send file as response, checking and setting caching headers
  88. * @param string $filepath of file to send
  89. */
  90. static public function sendFile( $filepath ) {
  91. \OC_Response::sendFile( $filepath );
  92. }
  93. /**
  94. * Set response expire time
  95. * @param string|\DateTime $expires date-time when the response expires
  96. * string for DateInterval from now
  97. * DateTime object when to expire response
  98. */
  99. static public function setExpiresHeader( $expires ) {
  100. \OC_Response::setExpiresHeader( $expires );
  101. }
  102. /**
  103. * Send redirect response
  104. * @param string $location to redirect to
  105. */
  106. static public function redirect( $location ) {
  107. \OC_Response::redirect( $location );
  108. }
  109. }