GCDWebServerRequest.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. Copyright (c) 2012-2013, 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 <Foundation/Foundation.h>
  26. @interface GCDWebServerRequest : NSObject {
  27. @private
  28. NSString* _method;
  29. NSURL* _url;
  30. NSDictionary* _headers;
  31. NSString* _path;
  32. NSDictionary* _query;
  33. NSString* _type;
  34. NSUInteger _length;
  35. }
  36. @property(nonatomic, readonly) NSString* method;
  37. @property(nonatomic, readonly) NSURL* URL;
  38. @property(nonatomic, readonly) NSDictionary* headers;
  39. @property(nonatomic, readonly) NSString* path;
  40. @property(nonatomic, readonly) NSDictionary* query; // May be nil
  41. @property(nonatomic, readonly) NSString* contentType; // Automatically parsed from headers (nil if request has no body)
  42. @property(nonatomic, readonly) NSUInteger contentLength; // Automatically parsed from headers
  43. - (id)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query;
  44. - (BOOL)hasBody; // Convenience method
  45. @end
  46. @interface GCDWebServerRequest (Subclassing)
  47. - (BOOL)open; // Implementation required
  48. - (NSInteger)write:(const void*)buffer maxLength:(NSUInteger)length; // Implementation required
  49. - (BOOL)close; // Implementation required
  50. @end
  51. @interface GCDWebServerDataRequest : GCDWebServerRequest {
  52. @private
  53. NSMutableData* _data;
  54. }
  55. @property(nonatomic, readonly) NSData* data; // Only valid after open / write / close sequence
  56. @end
  57. @interface GCDWebServerFileRequest : GCDWebServerRequest {
  58. @private
  59. NSString* _filePath;
  60. int _file;
  61. }
  62. @property(nonatomic, readonly) NSString* filePath; // Only valid after open / write / close sequence
  63. @end
  64. @interface GCDWebServerURLEncodedFormRequest : GCDWebServerDataRequest {
  65. @private
  66. NSDictionary* _arguments;
  67. }
  68. @property(nonatomic, readonly) NSDictionary* arguments; // Only valid after open / write / close sequence
  69. + (NSString*)mimeType;
  70. @end
  71. @interface GCDWebServerMultiPart : NSObject {
  72. @private
  73. NSString* _contentType;
  74. NSString* _mimeType;
  75. }
  76. @property(nonatomic, readonly) NSString* contentType; // May be nil
  77. @property(nonatomic, readonly) NSString* mimeType; // Defaults to "text/plain" per specifications if undefined
  78. @end
  79. @interface GCDWebServerMultiPartArgument : GCDWebServerMultiPart {
  80. @private
  81. NSData* _data;
  82. NSString* _string;
  83. }
  84. @property(nonatomic, readonly) NSData* data;
  85. @property(nonatomic, readonly) NSString* string; // May be nil (only valid for text mime types
  86. @end
  87. @interface GCDWebServerMultiPartFile : GCDWebServerMultiPart {
  88. @private
  89. NSString* _fileName;
  90. NSString* _temporaryPath;
  91. }
  92. @property(nonatomic, readonly) NSString* fileName; // May be nil
  93. @property(nonatomic, readonly) NSString* temporaryPath;
  94. @end
  95. @interface GCDWebServerMultiPartFormRequest : GCDWebServerRequest {
  96. @private
  97. NSData* _boundary;
  98. NSUInteger _parserState;
  99. NSMutableData* _parserData;
  100. NSString* _controlName;
  101. NSString* _fileName;
  102. NSString* _contentType;
  103. NSString* _tmpPath;
  104. int _tmpFile;
  105. NSMutableDictionary* _arguments;
  106. NSMutableDictionary* _files;
  107. }
  108. @property(nonatomic, readonly) NSDictionary* arguments; // Only valid after open / write / close sequence
  109. @property(nonatomic, readonly) NSDictionary* files; // Only valid after open / write / close sequence
  110. + (NSString*)mimeType;
  111. @end