2012-12-30 14:23:49 +08:00
/*
2014-02-07 10:44:04 +08:00
Copyright ( c ) 2012 - 2014 , Pierre - Olivier Latour
2012-12-30 14:23:49 +08:00
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
* Redistributions of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
* Redistributions in binary form must reproduce the above copyright
notice , this list of conditions and the following disclaimer in the
documentation and / or other materials provided with the distribution .
2013-12-30 11:02:01 +08:00
* The name of Pierre - Olivier Latour may not be used to endorse
or promote products derived from this software without specific
prior written permission .
2012-12-30 14:23:49 +08:00
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2013-12-30 11:02:01 +08:00
DISCLAIMED . IN NO EVENT SHALL PIERRE - OLIVIER LATOUR BE LIABLE FOR ANY
2012-12-30 14:23:49 +08:00
DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
# import <Foundation / Foundation.h>
2014-03-20 00:19:59 +08:00
@ interface GCDWebServerResponse : NSObject
2012-12-30 14:23:49 +08:00
@ property ( nonatomic , readonly ) NSString * contentType ;
@ property ( nonatomic , readonly ) NSUInteger contentLength ;
@ property ( nonatomic ) NSInteger statusCode ; // Default is 200
@ property ( nonatomic ) NSUInteger cacheControlMaxAge ; // Default is 0 seconds i.e. "no-cache"
@ property ( nonatomic , readonly ) NSDictionary * additionalHeaders ;
+ ( GCDWebServerResponse * ) response ;
2012-12-31 10:48:25 +08:00
- ( id ) init ;
- ( id ) initWithContentType : ( NSString * ) type contentLength : ( NSUInteger ) length ; // Pass nil contentType to indicate empty body
- ( void ) setValue : ( NSString * ) value forAdditionalHeader : ( NSString * ) header ;
- ( BOOL ) hasBody ; // Convenience method
2012-12-30 14:23:49 +08:00
@ end
@ interface GCDWebServerResponse ( Subclassing )
2012-12-31 10:48:25 +08:00
- ( BOOL ) open ; // Implementation required
- ( NSInteger ) read : ( void * ) buffer maxLength : ( NSUInteger ) length ; // Implementation required
- ( BOOL ) close ; // Implementation required
2012-12-30 14:23:49 +08:00
@ end
@ interface GCDWebServerResponse ( Extensions )
2012-12-31 10:48:25 +08:00
+ ( GCDWebServerResponse * ) responseWithStatusCode : ( NSInteger ) statusCode ;
+ ( GCDWebServerResponse * ) responseWithRedirect : ( NSURL * ) location permanent : ( BOOL ) permanent ;
- ( id ) initWithStatusCode : ( NSInteger ) statusCode ;
- ( id ) initWithRedirect : ( NSURL * ) location permanent : ( BOOL ) permanent ;
2012-12-30 14:23:49 +08:00
@ end
2014-03-20 00:19:59 +08:00
@ interface GCDWebServerDataResponse : GCDWebServerResponse
2012-12-31 10:48:25 +08:00
+ ( GCDWebServerDataResponse * ) responseWithData : ( NSData * ) data contentType : ( NSString * ) type ;
- ( id ) initWithData : ( NSData * ) data contentType : ( NSString * ) type ;
2012-12-30 14:23:49 +08:00
@ end
@ interface GCDWebServerDataResponse ( Extensions )
2012-12-31 10:48:25 +08:00
+ ( GCDWebServerDataResponse * ) responseWithText : ( NSString * ) text ;
+ ( GCDWebServerDataResponse * ) responseWithHTML : ( NSString * ) html ;
+ ( GCDWebServerDataResponse * ) responseWithHTMLTemplate : ( NSString * ) path variables : ( NSDictionary * ) variables ;
- ( id ) initWithText : ( NSString * ) text ; // Encodes using UTF-8
- ( id ) initWithHTML : ( NSString * ) html ; // Encodes using UTF-8
- ( id ) initWithHTMLTemplate : ( NSString * ) path variables : ( NSDictionary * ) variables ; // Simple template system that replaces all occurences of "%variable%" with corresponding value (encodes using UTF-8)
2012-12-30 14:23:49 +08:00
@ end
2014-03-20 00:19:59 +08:00
@ interface GCDWebServerFileResponse : GCDWebServerResponse
2012-12-31 10:48:25 +08:00
+ ( GCDWebServerFileResponse * ) responseWithFile : ( NSString * ) path ;
+ ( GCDWebServerFileResponse * ) responseWithFile : ( NSString * ) path isAttachment : ( BOOL ) attachment ;
2014-03-20 11:57:35 +08:00
+ ( GCDWebServerFileResponse * ) responseWithFile : ( NSString * ) path byteRange : ( NSRange ) range ;
+ ( GCDWebServerFileResponse * ) responseWithFile : ( NSString * ) path byteRange : ( NSRange ) range isAttachment : ( BOOL ) attachment ;
2012-12-31 10:48:25 +08:00
- ( id ) initWithFile : ( NSString * ) path ;
- ( id ) initWithFile : ( NSString * ) path isAttachment : ( BOOL ) attachment ;
2014-03-20 11:57:35 +08:00
- ( id ) initWithFile : ( NSString * ) path byteRange : ( NSRange ) range ; // Pass [NSNotFound, 0] to disable byte range entirely, [offset, length] to enable byte range from beginning of file or [NSNotFound, -bytes] from end of file
- ( id ) initWithFile : ( NSString * ) path byteRange : ( NSRange ) range isAttachment : ( BOOL ) attachment ;
2012-12-30 14:23:49 +08:00
@ end