GCDWebServerRequest.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (c) 2012-2014, 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. @property(nonatomic, readonly) NSString* method;
  28. @property(nonatomic, readonly) NSURL* URL;
  29. @property(nonatomic, readonly) NSDictionary* headers;
  30. @property(nonatomic, readonly) NSString* path;
  31. @property(nonatomic, readonly) NSDictionary* query; // May be nil
  32. @property(nonatomic, readonly) NSString* contentType; // Automatically parsed from headers (nil if request has no body)
  33. @property(nonatomic, readonly) NSUInteger contentLength; // Automatically parsed from headers
  34. @property(nonatomic, readonly) NSRange byteRange; // Automatically parsed from headers ([NSNotFound, 0] if request has no "Range" header, [offset, length] for byte range from beginning or [NSNotFound, -bytes] from end)
  35. - (id)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query;
  36. - (BOOL)hasBody; // Convenience method
  37. @end
  38. @interface GCDWebServerRequest (Subclassing)
  39. - (BOOL)open; // Implementation required
  40. - (NSInteger)write:(const void*)buffer maxLength:(NSUInteger)length; // Implementation required
  41. - (BOOL)close; // Implementation required
  42. @end
  43. @interface GCDWebServerDataRequest : GCDWebServerRequest
  44. @property(nonatomic, readonly) NSData* data; // Only valid after open / write / close sequence
  45. @end
  46. @interface GCDWebServerFileRequest : GCDWebServerRequest
  47. @property(nonatomic, readonly) NSString* filePath; // Only valid after open / write / close sequence
  48. @end
  49. @interface GCDWebServerURLEncodedFormRequest : GCDWebServerDataRequest
  50. @property(nonatomic, readonly) NSDictionary* arguments; // Only valid after open / write / close sequence
  51. + (NSString*)mimeType;
  52. @end
  53. @interface GCDWebServerMultiPart : NSObject
  54. @property(nonatomic, readonly) NSString* contentType; // May be nil
  55. @property(nonatomic, readonly) NSString* mimeType; // Defaults to "text/plain" per specifications if undefined
  56. @end
  57. @interface GCDWebServerMultiPartArgument : GCDWebServerMultiPart
  58. @property(nonatomic, readonly) NSData* data;
  59. @property(nonatomic, readonly) NSString* string; // May be nil (only valid for text mime types)
  60. @end
  61. @interface GCDWebServerMultiPartFile : GCDWebServerMultiPart
  62. @property(nonatomic, readonly) NSString* fileName; // May be nil
  63. @property(nonatomic, readonly) NSString* temporaryPath;
  64. @end
  65. @interface GCDWebServerMultiPartFormRequest : GCDWebServerRequest
  66. @property(nonatomic, readonly) NSDictionary* arguments; // Only valid after open / write / close sequence
  67. @property(nonatomic, readonly) NSDictionary* files; // Only valid after open / write / close sequence
  68. + (NSString*)mimeType;
  69. @end