response.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Public interface of ownCloud for apps to use.
  24. * Response Class.
  25. *
  26. */
  27. // use OCP namespace for all classes that are considered public.
  28. // This means that they should be used by apps instead of the internal ownCloud classes
  29. namespace OCP;
  30. /**
  31. * This class provides convinient functions to send the correct http response headers
  32. */
  33. class Response {
  34. /**
  35. * @brief Enable response caching by sending correct HTTP headers
  36. * @param $cache_time time to cache the response
  37. * >0 cache time in seconds
  38. * 0 and <0 enable default browser caching
  39. * null cache indefinitly
  40. */
  41. static public function enableCaching( $cache_time = null ) {
  42. return(\OC_Response::enableCaching( $cache_time ));
  43. }
  44. /**
  45. * Checks and set Last-Modified header, when the request matches sends a
  46. * 'not modified' response
  47. * @param $lastModified time when the reponse was last modified
  48. */
  49. static public function setLastModifiedHeader( $lastModified ) {
  50. return(\OC_Response::setLastModifiedHeader( $lastModified ));
  51. }
  52. /**
  53. * @brief disable browser caching
  54. * @see enableCaching with cache_time = 0
  55. */
  56. static public function disableCaching() {
  57. return(\OC_Response::disableCaching());
  58. }
  59. /**
  60. * Checks and set ETag header, when the request matches sends a
  61. * 'not modified' response
  62. * @param $etag token to use for modification check
  63. */
  64. static public function setETagHeader( $etag ) {
  65. return(\OC_Response::setETagHeader( $etag ));
  66. }
  67. /**
  68. * @brief Send file as response, checking and setting caching headers
  69. * @param $filepath of file to send
  70. */
  71. static public function sendFile( $filepath ) {
  72. return(\OC_Response::sendFile( $filepath ));
  73. }
  74. /**
  75. * @brief Set reponse expire time
  76. * @param $expires date-time when the response expires
  77. * string for DateInterval from now
  78. * DateTime object when to expire response
  79. */
  80. static public function setExpiresHeader( $expires ) {
  81. return(\OC_Response::setExpiresHeader( $expires ));
  82. }
  83. /**
  84. * @brief Send redirect response
  85. * @param $location to redirect to
  86. */
  87. static public function redirect( $location ) {
  88. return(\OC_Response::redirect( $location ));
  89. }
  90. }