Mercurial > projects > dstep
comparison dstep/foundation/NSURLProtocol.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 19885b43130e |
comparison
equal
deleted
inserted
replaced
13:4f583f7e242e | 14:89f3c3ef1fd2 |
---|---|
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.NSURLProtocol; | |
8 | |
9 import dstep.AvailabilityMacros; | |
10 import dstep.foundation.NSCachedURLResponse; | |
11 import dstep.foundation.NSError; | |
12 import dstep.foundation.NSMutableURLRequest; | |
13 import dstep.foundation.NSObject; | |
14 import dstep.foundation.NSURLAuthenticationChallenge; | |
15 import dstep.foundation.NSURLCache; | |
16 import dstep.foundation.NSURLConnection; | |
17 import dstep.foundation.NSURLProtocolInternal; | |
18 import dstep.foundation.NSURLRequest; | |
19 import dstep.foundation.NSURLResponse; | |
20 import dstep.objc.bridge.Bridge; | |
21 import dstep.objc.objc : id; | |
22 | |
23 class NSURLProtocol : NSObject | |
24 { | |
25 mixin ObjcWrap; | |
26 | |
27 Object initWithRequest (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client) | |
28 { | |
29 return invokeObjcSelf!(Object, "initWithRequest:cachedResponse:client:", NSURLRequest, NSCachedURLResponse, INSURLProtocolClient)(request, cachedResponse, client); | |
30 } | |
31 | |
32 this (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client) | |
33 { | |
34 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
35 id result = Bridge.invokeObjcMethod!(id, "initWithRequest:cachedResponse:client:", NSURLRequest, NSCachedURLResponse, INSURLProtocolClient)(objcObject, request, cachedResponse, client); | |
36 | |
37 if (result) | |
38 objcObject = ret; | |
39 | |
40 dObject = this; | |
41 } | |
42 | |
43 INSURLProtocolClient client () | |
44 { | |
45 return invokeObjcSelf!(INSURLProtocolClient, "client"); | |
46 } | |
47 | |
48 NSURLRequest request () | |
49 { | |
50 return invokeObjcSelf!(NSURLRequest, "request"); | |
51 } | |
52 | |
53 NSCachedURLResponse cachedResponse () | |
54 { | |
55 return invokeObjcSelf!(NSCachedURLResponse, "cachedResponse"); | |
56 } | |
57 | |
58 static bool canInitWithRequest (NSURLRequest request) | |
59 { | |
60 return invokeObjcSelfClass!(bool, "canInitWithRequest:", NSURLRequest)(request); | |
61 } | |
62 | |
63 static NSURLRequest canonicalRequestForRequest (NSURLRequest request) | |
64 { | |
65 return invokeObjcSelfClass!(NSURLRequest, "canonicalRequestForRequest:", NSURLRequest)(request); | |
66 } | |
67 | |
68 static bool requestIsCacheEquivalent (NSURLRequest a, NSURLRequest b) | |
69 { | |
70 return invokeObjcSelfClass!(bool, "requestIsCacheEquivalent:toRequest:", NSURLRequest, NSURLRequest)(a, b); | |
71 } | |
72 | |
73 void startLoading () | |
74 { | |
75 return invokeObjcSelf!(void, "startLoading"); | |
76 } | |
77 | |
78 void stopLoading () | |
79 { | |
80 return invokeObjcSelf!(void, "stopLoading"); | |
81 } | |
82 | |
83 static Object propertyForKey (NSString key, NSURLRequest request) | |
84 { | |
85 return invokeObjcSelfClass!(Object, "propertyForKey:inRequest:", NSString, NSURLRequest)(key, request); | |
86 } | |
87 | |
88 static void setProperty (Object value, NSString key, NSMutableURLRequest request) | |
89 { | |
90 return invokeObjcSelfClass!(void, "setProperty:forKey:inRequest:", Object, NSString, NSMutableURLRequest)(value, key, request); | |
91 } | |
92 | |
93 static void removePropertyForKey (NSString key, NSMutableURLRequest request) | |
94 { | |
95 return invokeObjcSelfClass!(void, "removePropertyForKey:inRequest:", NSString, NSMutableURLRequest)(key, request); | |
96 } | |
97 | |
98 static bool registerClass (Class protocolClass) | |
99 { | |
100 return invokeObjcSelfClass!(bool, "registerClass:", Class)(protocolClass); | |
101 } | |
102 | |
103 static void unregisterClass (Class protocolClass) | |
104 { | |
105 return invokeObjcSelfClass!(void, "unregisterClass:", Class)(protocolClass); | |
106 } | |
107 } | |
108 | |
109 interface INSURLProtocolClient : INSObject | |
110 { | |
111 void URLProtocol (NSURLProtocol protocol, NSURLRequest request, NSURLResponse redirectResponse); | |
112 void URLProtocol (NSURLProtocol protocol, NSCachedURLResponse cachedResponse); | |
113 void URLProtocol (NSURLProtocol protocol, NSURLResponse response, uint policy); | |
114 void URLProtocol (NSURLProtocol protocol, NSData data); | |
115 void URLProtocolDidFinishLoading (NSURLProtocol protocol); | |
116 void URLProtocol (NSURLProtocol protocol, NSError error); | |
117 void URLProtocol (NSURLProtocol protocol, NSURLAuthenticationChallenge challenge); | |
118 void URLProtocol (NSURLProtocol protocol, NSURLAuthenticationChallenge challenge); | |
119 } | |
120 |