-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHTTPDynamicFileResponse.h
69 lines (57 loc) · 1.76 KB
/
HTTPDynamicFileResponse.h
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
#import <Foundation/Foundation.h>
#import "HTTPResponse.h"
@class HTTPConnection;
/**
* This class is designed to assist with dynamic content.
* Imagine you have a file that you want to make dynamic:
*
* <html>
* <body>
* <h1>ComputerName Control Panel</h1>
* ...
* <li>System Time: SysTime</li>
* </body>
* </html>
*
* Now you could generate the entire file in Objective-C,
* but this would be a horribly tedious process.
* Beside, you want to design the file with professional tools to make it look pretty.
*
* So all you have to do is escape your dynamic content like this:
*
* ...
* <h1>%%ComputerName%% Control Panel</h1>
* ...
* <li>System Time: %%SysTime%%</li>
*
* And then you create an instance of this class with:
*
* - separator = @"%%"
* - replacementDictionary = { "ComputerName"="Black MacBook", "SysTime"="2010-04-30 03:18:24" }
*
* This class will then perform the replacements for you, on the fly, as it reads the file data.
* This class is also asynchronous, so it will perform the file IO on a background thread via an NSOperationQueue.
**/
@interface HTTPDynamicFileResponse : NSObject <HTTPResponse>
{
HTTPConnection *connection;
NSThread *connectionThread;
NSArray *connectionRunLoopModes;
NSString *filePath;
NSFileHandle *fileHandle;
UInt64 fileLength;
UInt64 fileReadOffset;
UInt64 connectionReadOffset;
NSMutableData *bufferedData;
NSUInteger available;
BOOL asyncReadInProgress;
NSData *separator;
NSDictionary *replacementDict;
}
- (id)initWithFilePath:(NSString *)filePath
forConnection:(HTTPConnection *)connection
runLoopModes:(NSArray *)modes
separator:(NSString *)separatorStr
replacementDictionary:(NSDictionary *)dictionary;
- (NSString *)filePath;
@end