GCDWebServerFileResponse.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Copyright (c) 2012-2015, Pierre-Olivier Latour
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * The name of Pierre-Olivier Latour may not be used to endorse
  12. or promote products derived from this software without specific
  13. prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import "GCDWebServerResponse.h"
  26. /**
  27. * The GCDWebServerFileResponse subclass of GCDWebServerResponse reads the body
  28. * of the HTTP response from a file on disk.
  29. *
  30. * It will automatically set the contentType, lastModifiedDate and eTag
  31. * properties of the GCDWebServerResponse according to the file extension and
  32. * metadata.
  33. */
  34. @interface GCDWebServerFileResponse : GCDWebServerResponse
  35. /**
  36. * Creates a response with the contents of a file.
  37. */
  38. + (instancetype)responseWithFile:(NSString*)path;
  39. /**
  40. * Creates a response like +responseWithFile: and sets the "Content-Disposition"
  41. * HTTP header for a download if the "attachment" argument is YES.
  42. */
  43. + (instancetype)responseWithFile:(NSString*)path isAttachment:(BOOL)attachment;
  44. /**
  45. * Creates a response like +responseWithFile: but restricts the file contents
  46. * to a specific byte range.
  47. *
  48. * See -initWithFile:byteRange: for details.
  49. */
  50. + (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range;
  51. /**
  52. * Creates a response like +responseWithFile:byteRange: and sets the
  53. * "Content-Disposition" HTTP header for a download if the "attachment"
  54. * argument is YES.
  55. */
  56. + (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment;
  57. /**
  58. * Initializes a response with the contents of a file.
  59. */
  60. - (instancetype)initWithFile:(NSString*)path;
  61. /**
  62. * Initializes a response like +responseWithFile: and sets the
  63. * "Content-Disposition" HTTP header for a download if the "attachment"
  64. * argument is YES.
  65. */
  66. - (instancetype)initWithFile:(NSString*)path isAttachment:(BOOL)attachment;
  67. /**
  68. * Initializes a response like -initWithFile: but restricts the file contents
  69. * to a specific byte range. This range should be set to (NSUIntegerMax, 0) for
  70. * the full file, (offset, length) if expressed from the beginning of the file,
  71. * or (NSUIntegerMax, length) if expressed from the end of the file. The "offset"
  72. * and "length" values will be automatically adjusted to be compatible with the
  73. * actual size of the file.
  74. *
  75. * This argument would typically be set to the value of the byteRange property
  76. * of the current GCDWebServerRequest.
  77. */
  78. - (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range;
  79. /**
  80. * This method is the designated initializer for the class.
  81. */
  82. - (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment;
  83. @end