-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUUHttpResponseHandler.h
More file actions
83 lines (63 loc) · 2.65 KB
/
UUHttpResponseHandler.h
File metadata and controls
83 lines (63 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// UUHttpResponseHandler.h
// Useful Utilities - HTTP response de-serialization protocol
//
// License:
// You are free to use this code for whatever purposes you desire. The only requirement is that you smile everytime you use it.
//
// Contact: @cheesemaker or jon@threejacks.com
//
#import <UIKit/UIKit.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Currently supported HTTP verbs
typedef enum
{
UUHttpMethodGet,
UUHttpMethodPut,
UUHttpMethodPost,
UUHttpMethodDelete,
UUHttpMethodHead,
UUHttpMethodPatch,
} UUHttpMethod;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Common HTTP response Codes
typedef enum
{
UUHttpResponseCodeOK = 200,
UUHttpResponseCodeCreated = 201,
} UUHttpResponseCode;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// HTTP String Constants
extern NSString * const kUUContentTypeApplicationJson;
extern NSString * const kUUContentTypeTextJson;
extern NSString * const kUUContentTypeTextHtml;
extern NSString * const kUUContentTypeTextPlain;
extern NSString * const kUUContentTypeBinary;
extern NSString * const kUUContentTypeImagePng;
extern NSString * const kUUContentTypeImageJpeg;
extern NSString * const kUUContentLengthHeader;
extern NSString * const kUUContentTypeHeader;
extern NSString * const kUUAcceptHeader;
extern NSString * const kUUHttpMethodGet;
extern NSString * const kUUHttpMethodPut;
extern NSString * const kUUHttpMethodPost;
extern NSString * const kUUHttpMethodDelete;
extern NSString * const kUUHttpMethodHead;
extern NSString * const kUUHttpMethodPatch;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Register response handlers to construct objects from mime types
@protocol UUHttpResponseHandler <NSObject>
@required
- (NSArray*) supportedMimeTypes;
- (id) parseResponse:(NSData*)rxBuffer response:(NSHTTPURLResponse*)response forRequest:(NSURLRequest*)request;
@end
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Built-in response handlers
@interface UUTextResponseHandler : NSObject<UUHttpResponseHandler>
@end
@interface UUBinaryResponseHandler : NSObject<UUHttpResponseHandler>
@end
@interface UUJsonResponseHandler : NSObject<UUHttpResponseHandler>
@end
@interface UUImageResponseHandler : NSObject<UUHttpResponseHandler>
@end