14
|
1 /**
|
|
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
|
|
3 * Authors: Jacob Carlborg
|
|
4 * Version: Initial created: Aug 3, 2009
|
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
|
|
6 */
|
|
7 module dstep.foundation.NSURLRequest;
|
|
8
|
|
9 import dstep.AvailabilityMacros;
|
|
10 import dstep.foundation.NSData;
|
|
11 import dstep.foundation.NSDate;
|
|
12 import dstep.foundation.NSDictionary;
|
|
13 import dstep.foundation.NSInputStream;
|
|
14 import dstep.foundation.NSObject;
|
|
15 import dstep.foundation.NSString;
|
|
16 import dstep.foundation.NSURL;
|
|
17 import dstep.foundation.NSURLRequestInternal;
|
|
18 import dstep.objc.bridge.Bridge;
|
|
19 import dstep.objc.objc : id;
|
|
20
|
|
21 alias NSUInteger NSURLRequestCachePolicy;
|
|
22
|
|
23 enum
|
|
24 {
|
|
25 NSURLRequestUseProtocolCachePolicy = 0,
|
|
26 NSURLRequestReloadIgnoringLocalCacheData = 1,
|
|
27 NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4,
|
|
28 NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData,
|
|
29 NSURLRequestReturnCacheDataElseLoad = 2,
|
|
30 NSURLRequestReturnCacheDataDontLoad = 3,
|
|
31 NSURLRequestReloadRevalidatingCacheData = 5
|
|
32 }
|
|
33
|
|
34 class NSURLRequest : NSObject, INSCoding, INSCopying, INSMutableCopying
|
|
35 {
|
|
36 mixin ObjcWrap;
|
|
37 mixin TNSHTTPURLRequest;
|
|
38
|
|
39 static Object requestWithURL (NSURL URL)
|
|
40 {
|
|
41 return invokeObjcSelfClass!(Object, "requestWithURL:", NSURL)(URL);
|
|
42 }
|
|
43
|
|
44 static Object requestWithURL (NSURL URL, uint cachePolicy, double timeoutInterval)
|
|
45 {
|
|
46 return invokeObjcSelfClass!(Object, "requestWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval);
|
|
47 }
|
|
48
|
|
49 Object initWithURL (NSURL URL)
|
|
50 {
|
|
51 return invokeObjcSelf!(Object, "initWithURL:", NSURL)(URL);
|
|
52 }
|
|
53
|
|
54 this (NSURL URL)
|
|
55 {
|
|
56 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
57 id result = Bridge.invokeObjcMethod!(id, "initWithURL:", NSURL)(objcObject, URL);
|
|
58
|
|
59 if (result)
|
|
60 objcObject = ret;
|
|
61
|
|
62 dObject = this;
|
|
63 }
|
|
64
|
|
65 Object initWithURL (NSURL URL, uint cachePolicy, double timeoutInterval)
|
|
66 {
|
|
67 return invokeObjcSelf!(Object, "initWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval);
|
|
68 }
|
|
69
|
|
70 this (NSURL URL, uint cachePolicy, double timeoutInterval)
|
|
71 {
|
|
72 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
73 id result = Bridge.invokeObjcMethod!(id, "initWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(objcObject, URL, cachePolicy, timeoutInterval);
|
|
74
|
|
75 if (result)
|
|
76 objcObject = ret;
|
|
77
|
|
78 dObject = this;
|
|
79 }
|
|
80
|
|
81 NSURL URL ()
|
|
82 {
|
|
83 return invokeObjcSelf!(NSURL, "URL");
|
|
84 }
|
|
85
|
|
86 uint cachePolicy ()
|
|
87 {
|
|
88 return invokeObjcSelf!(uint, "cachePolicy");
|
|
89 }
|
|
90
|
|
91 double timeoutInterval ()
|
|
92 {
|
|
93 return invokeObjcSelf!(double, "timeoutInterval");
|
|
94 }
|
|
95
|
|
96 NSURL mainDocumentURL ()
|
|
97 {
|
|
98 return invokeObjcSelf!(NSURL, "mainDocumentURL");
|
|
99 }
|
|
100
|
|
101 void encodeWithCoder (NSCoder aCoder)
|
|
102 {
|
|
103 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
|
|
104 }
|
|
105
|
|
106 Object initWithCoder (NSCoder aDecoder)
|
|
107 {
|
|
108 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
|
|
109 }
|
|
110
|
|
111 this (NSCoder aDecoder)
|
|
112 {
|
|
113 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
114 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
|
|
115
|
|
116 if (result)
|
|
117 objcObject = ret;
|
|
118
|
|
119 dObject = this;
|
|
120 }
|
|
121
|
|
122 Object copyWithZone (NSZone* zone)
|
|
123 {
|
|
124 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
|
|
125 }
|
|
126
|
|
127 Object mutableCopyWithZone (NSZone* zone)
|
|
128 {
|
|
129 return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone);
|
|
130 }
|
|
131 }
|
|
132
|
|
133 class NSMutableURLRequest : NSURLRequest
|
|
134 {
|
|
135 mixin ObjcWrap;
|
|
136 mixin TNSMutableHTTPURLRequest;
|
|
137
|
|
138 void setURL (NSURL URL)
|
|
139 {
|
|
140 return invokeObjcSelf!(void, "setURL:", NSURL)(URL);
|
|
141 }
|
|
142
|
|
143 void setCachePolicy (uint policy)
|
|
144 {
|
|
145 return invokeObjcSelf!(void, "setCachePolicy:", uint)(policy);
|
|
146 }
|
|
147
|
|
148 void setTimeoutInterval (double seconds)
|
|
149 {
|
|
150 return invokeObjcSelf!(void, "setTimeoutInterval:", double)(seconds);
|
|
151 }
|
|
152
|
|
153 void setMainDocumentURL (NSURL URL)
|
|
154 {
|
|
155 return invokeObjcSelf!(void, "setMainDocumentURL:", NSURL)(URL);
|
|
156 }
|
|
157 }
|
|
158
|
|
159 template TNSHTTPURLRequest ()
|
|
160 {
|
|
161 NSString HTTPMethod ()
|
|
162 {
|
|
163 return invokeObjcSelf!(NSString, "HTTPMethod");
|
|
164 }
|
|
165
|
|
166 NSDictionary allHTTPHeaderFields ()
|
|
167 {
|
|
168 return invokeObjcSelf!(NSDictionary, "allHTTPHeaderFields");
|
|
169 }
|
|
170
|
|
171 NSString valueForHTTPHeaderField (NSString field)
|
|
172 {
|
|
173 return invokeObjcSelf!(NSString, "valueForHTTPHeaderField:", NSString)(field);
|
|
174 }
|
|
175
|
|
176 NSData HTTPBody ()
|
|
177 {
|
|
178 return invokeObjcSelf!(NSData, "HTTPBody");
|
|
179 }
|
|
180
|
|
181 NSInputStream HTTPBodyStream ()
|
|
182 {
|
|
183 return invokeObjcSelf!(NSInputStream, "HTTPBodyStream");
|
|
184 }
|
|
185
|
|
186 bool HTTPShouldHandleCookies ()
|
|
187 {
|
|
188 return invokeObjcSelf!(bool, "HTTPShouldHandleCookies");
|
|
189 }
|
|
190 }
|
|
191
|
|
192 template TNSMutableHTTPURLRequest ()
|
|
193 {
|
|
194 void setHTTPMethod (NSString method)
|
|
195 {
|
|
196 return invokeObjcSelf!(void, "setHTTPMethod:", NSString)(method);
|
|
197 }
|
|
198
|
|
199 void setAllHTTPHeaderFields (NSDictionary headerFields)
|
|
200 {
|
|
201 return invokeObjcSelf!(void, "setAllHTTPHeaderFields:", NSDictionary)(headerFields);
|
|
202 }
|
|
203
|
|
204 void setValue (NSString value, NSString field)
|
|
205 {
|
|
206 return invokeObjcSelf!(void, "setValue:forHTTPHeaderField:", NSString, NSString)(value, field);
|
|
207 }
|
|
208
|
|
209 void addValue (NSString value, NSString field)
|
|
210 {
|
|
211 return invokeObjcSelf!(void, "addValue:forHTTPHeaderField:", NSString, NSString)(value, field);
|
|
212 }
|
|
213
|
|
214 void setHTTPBody (NSData data)
|
|
215 {
|
|
216 return invokeObjcSelf!(void, "setHTTPBody:", NSData)(data);
|
|
217 }
|
|
218
|
|
219 void setHTTPBodyStream (NSInputStream inputStream)
|
|
220 {
|
|
221 return invokeObjcSelf!(void, "setHTTPBodyStream:", NSInputStream)(inputStream);
|
|
222 }
|
|
223
|
|
224 void setHTTPShouldHandleCookies (bool should)
|
|
225 {
|
|
226 return invokeObjcSelf!(void, "setHTTPShouldHandleCookies:", bool)(should);
|
|
227 }
|
|
228 }
|
|
229
|