GCDWebServerMultiPartFormRequest.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 "GCDWebServerRequest.h"
  26. /**
  27. * The GCDWebServerMultiPart class is an abstract class that wraps the content
  28. * of a part.
  29. */
  30. @interface GCDWebServerMultiPart : NSObject
  31. /**
  32. * Returns the control name retrieved from the part headers.
  33. */
  34. @property(nonatomic, readonly) NSString* controlName;
  35. /**
  36. * Returns the content type retrieved from the part headers or "text/plain"
  37. * if not available (per HTTP specifications).
  38. */
  39. @property(nonatomic, readonly) NSString* contentType;
  40. /**
  41. * Returns the MIME type component of the content type for the part.
  42. */
  43. @property(nonatomic, readonly) NSString* mimeType;
  44. @end
  45. /**
  46. * The GCDWebServerMultiPartArgument subclass of GCDWebServerMultiPart wraps
  47. * the content of a part as data in memory.
  48. */
  49. @interface GCDWebServerMultiPartArgument : GCDWebServerMultiPart
  50. /**
  51. * Returns the data for the part.
  52. */
  53. @property(nonatomic, readonly) NSData* data;
  54. /**
  55. * Returns the data for the part interpreted as text. If the content
  56. * type of the part is not a text one, or if an error occurs, nil is returned.
  57. *
  58. * The text encoding used to interpret the data is extracted from the
  59. * "Content-Type" header or defaults to UTF-8.
  60. */
  61. @property(nonatomic, readonly) NSString* string;
  62. @end
  63. /**
  64. * The GCDWebServerMultiPartFile subclass of GCDWebServerMultiPart wraps
  65. * the content of a part as a file on disk.
  66. */
  67. @interface GCDWebServerMultiPartFile : GCDWebServerMultiPart
  68. /**
  69. * Returns the file name retrieved from the part headers.
  70. */
  71. @property(nonatomic, readonly) NSString* fileName;
  72. /**
  73. * Returns the path to the temporary file containing the part data.
  74. *
  75. * @warning This temporary file will be automatically deleted when the
  76. * GCDWebServerMultiPartFile is deallocated. If you want to preserve this file,
  77. * you must move it to a different location beforehand.
  78. */
  79. @property(nonatomic, readonly) NSString* temporaryPath;
  80. @end
  81. /**
  82. * The GCDWebServerMultiPartFormRequest subclass of GCDWebServerRequest
  83. * parses the body of the HTTP request as a multipart encoded form.
  84. */
  85. @interface GCDWebServerMultiPartFormRequest : GCDWebServerRequest
  86. /**
  87. * Returns the argument parts from the multipart encoded form as
  88. * name / GCDWebServerMultiPartArgument pairs.
  89. */
  90. @property(nonatomic, readonly) NSArray* arguments;
  91. /**
  92. * Returns the files parts from the multipart encoded form as
  93. * name / GCDWebServerMultiPartFile pairs.
  94. */
  95. @property(nonatomic, readonly) NSArray* files;
  96. /**
  97. * Returns the MIME type for multipart encoded forms
  98. * i.e. "multipart/form-data".
  99. */
  100. + (NSString*)mimeType;
  101. /**
  102. * Returns the first argument for a given control name or nil if not found.
  103. */
  104. - (GCDWebServerMultiPartArgument*)firstArgumentForControlName:(NSString*)name;
  105. /**
  106. * Returns the first file for a given control name or nil if not found.
  107. */
  108. - (GCDWebServerMultiPartFile*)firstFileForControlName:(NSString*)name;
  109. @end