diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstep/foundation/NSURLProtocol.d	Mon Aug 03 15:23:15 2009 +0200
@@ -0,0 +1,120 @@
+/**
+ * Copyright: Copyright (c) 2009 Jacob Carlborg.
+ * Authors: Jacob Carlborg
+ * Version: Initial created: Aug 3, 2009 
+ * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
+ */
+module dstep.foundation.NSURLProtocol;
+
+import dstep.AvailabilityMacros;
+import dstep.foundation.NSCachedURLResponse;
+import dstep.foundation.NSError;
+import dstep.foundation.NSMutableURLRequest;
+import dstep.foundation.NSObject;
+import dstep.foundation.NSURLAuthenticationChallenge;
+import dstep.foundation.NSURLCache;
+import dstep.foundation.NSURLConnection;
+import dstep.foundation.NSURLProtocolInternal;
+import dstep.foundation.NSURLRequest;
+import dstep.foundation.NSURLResponse;
+import dstep.objc.bridge.Bridge;
+import dstep.objc.objc : id;
+
+class NSURLProtocol : NSObject
+{
+	mixin ObjcWrap;
+
+	Object initWithRequest (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client)
+	{
+		return invokeObjcSelf!(Object, "initWithRequest:cachedResponse:client:", NSURLRequest, NSCachedURLResponse, INSURLProtocolClient)(request, cachedResponse, client);
+	}
+
+	this (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithRequest:cachedResponse:client:", NSURLRequest, NSCachedURLResponse, INSURLProtocolClient)(objcObject, request, cachedResponse, client);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	INSURLProtocolClient client ()
+	{
+		return invokeObjcSelf!(INSURLProtocolClient, "client");
+	}
+
+	NSURLRequest request ()
+	{
+		return invokeObjcSelf!(NSURLRequest, "request");
+	}
+
+	NSCachedURLResponse cachedResponse ()
+	{
+		return invokeObjcSelf!(NSCachedURLResponse, "cachedResponse");
+	}
+
+	static bool canInitWithRequest (NSURLRequest request)
+	{
+		return invokeObjcSelfClass!(bool, "canInitWithRequest:", NSURLRequest)(request);
+	}
+
+	static NSURLRequest canonicalRequestForRequest (NSURLRequest request)
+	{
+		return invokeObjcSelfClass!(NSURLRequest, "canonicalRequestForRequest:", NSURLRequest)(request);
+	}
+
+	static bool requestIsCacheEquivalent (NSURLRequest a, NSURLRequest b)
+	{
+		return invokeObjcSelfClass!(bool, "requestIsCacheEquivalent:toRequest:", NSURLRequest, NSURLRequest)(a, b);
+	}
+
+	void startLoading ()
+	{
+		return invokeObjcSelf!(void, "startLoading");
+	}
+
+	void stopLoading ()
+	{
+		return invokeObjcSelf!(void, "stopLoading");
+	}
+
+	static Object propertyForKey (NSString key, NSURLRequest request)
+	{
+		return invokeObjcSelfClass!(Object, "propertyForKey:inRequest:", NSString, NSURLRequest)(key, request);
+	}
+
+	static void setProperty (Object value, NSString key, NSMutableURLRequest request)
+	{
+		return invokeObjcSelfClass!(void, "setProperty:forKey:inRequest:", Object, NSString, NSMutableURLRequest)(value, key, request);
+	}
+
+	static void removePropertyForKey (NSString key, NSMutableURLRequest request)
+	{
+		return invokeObjcSelfClass!(void, "removePropertyForKey:inRequest:", NSString, NSMutableURLRequest)(key, request);
+	}
+
+	static bool registerClass (Class protocolClass)
+	{
+		return invokeObjcSelfClass!(bool, "registerClass:", Class)(protocolClass);
+	}
+
+	static void unregisterClass (Class protocolClass)
+	{
+		return invokeObjcSelfClass!(void, "unregisterClass:", Class)(protocolClass);
+	}
+}
+
+interface INSURLProtocolClient : INSObject
+{
+	void URLProtocol (NSURLProtocol protocol, NSURLRequest request, NSURLResponse redirectResponse);
+	void URLProtocol (NSURLProtocol protocol, NSCachedURLResponse cachedResponse);
+	void URLProtocol (NSURLProtocol protocol, NSURLResponse response, uint policy);
+	void URLProtocol (NSURLProtocol protocol, NSData data);
+	void URLProtocolDidFinishLoading (NSURLProtocol protocol);
+	void URLProtocol (NSURLProtocol protocol, NSError error);
+	void URLProtocol (NSURLProtocol protocol, NSURLAuthenticationChallenge challenge);
+	void URLProtocol (NSURLProtocol protocol, NSURLAuthenticationChallenge challenge);
+}
+