1
0

response.php 4.1 KB

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