GCDWebServerDataResponse.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 GCDWebServerDataResponse subclass of GCDWebServerResponse reads the body
  28. * of the HTTP response from memory.
  29. */
  30. @interface GCDWebServerDataResponse : GCDWebServerResponse
  31. /**
  32. * Creates a response with data in memory and a given content type.
  33. */
  34. + (instancetype)responseWithData:(NSData*)data contentType:(NSString*)type;
  35. /**
  36. * This method is the designated initializer for the class.
  37. */
  38. - (instancetype)initWithData:(NSData*)data contentType:(NSString*)type;
  39. @end
  40. @interface GCDWebServerDataResponse (Extensions)
  41. /**
  42. * Creates a data response from text encoded using UTF-8.
  43. */
  44. + (instancetype)responseWithText:(NSString*)text;
  45. /**
  46. * Creates a data response from HTML encoded using UTF-8.
  47. */
  48. + (instancetype)responseWithHTML:(NSString*)html;
  49. /**
  50. * Creates a data response from an HTML template encoded using UTF-8.
  51. * See -initWithHTMLTemplate:variables: for details.
  52. */
  53. + (instancetype)responseWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables;
  54. /**
  55. * Creates a data response from a serialized JSON object and the default
  56. * "application/json" content type.
  57. */
  58. + (instancetype)responseWithJSONObject:(id)object;
  59. /**
  60. * Creates a data response from a serialized JSON object and a custom
  61. * content type.
  62. */
  63. + (instancetype)responseWithJSONObject:(id)object contentType:(NSString*)type;
  64. /**
  65. * Initializes a data response from text encoded using UTF-8.
  66. */
  67. - (instancetype)initWithText:(NSString*)text;
  68. /**
  69. * Initializes a data response from HTML encoded using UTF-8.
  70. */
  71. - (instancetype)initWithHTML:(NSString*)html;
  72. /**
  73. * Initializes a data response from an HTML template encoded using UTF-8.
  74. *
  75. * All occurences of "%variable%" within the HTML template are replaced with
  76. * their corresponding values.
  77. */
  78. - (instancetype)initWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables;
  79. /**
  80. * Initializes a data response from a serialized JSON object and the default
  81. * "application/json" content type.
  82. */
  83. - (instancetype)initWithJSONObject:(id)object;
  84. /**
  85. * Initializes a data response from a serialized JSON object and a custom
  86. * content type.
  87. */
  88. - (instancetype)initWithJSONObject:(id)object contentType:(NSString*)type;
  89. @end