objc2_foundation/generated/
NSURLProtocol.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9extern_protocol!(
10    /// NSURLProtocolClient provides the interface to the URL
11    /// loading system that is intended for use by NSURLProtocol
12    /// implementors.
13    ///
14    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlprotocolclient?language=objc)
15    pub unsafe trait NSURLProtocolClient: NSObjectProtocol {
16        #[cfg(all(feature = "NSURLRequest", feature = "NSURLResponse"))]
17        /// Indicates to an NSURLProtocolClient that a redirect has
18        /// occurred.
19        ///
20        /// Parameter `protocol`: the NSURLProtocol object sending the message.
21        ///
22        /// Parameter `request`: the NSURLRequest to which the protocol implementation
23        /// has redirected.
24        #[unsafe(method(URLProtocol:wasRedirectedToRequest:redirectResponse:))]
25        #[unsafe(method_family = none)]
26        unsafe fn URLProtocol_wasRedirectedToRequest_redirectResponse(
27            &self,
28            protocol: &NSURLProtocol,
29            request: &NSURLRequest,
30            redirect_response: &NSURLResponse,
31        );
32
33        #[cfg(feature = "NSURLCache")]
34        /// Indicates to an NSURLProtocolClient that the protocol
35        /// implementation has examined a cached response and has
36        /// determined that it is valid.
37        ///
38        /// Parameter `protocol`: the NSURLProtocol object sending the message.
39        ///
40        /// Parameter `cachedResponse`: the NSCachedURLResponse object that has
41        /// examined and is valid.
42        #[unsafe(method(URLProtocol:cachedResponseIsValid:))]
43        #[unsafe(method_family = none)]
44        unsafe fn URLProtocol_cachedResponseIsValid(
45            &self,
46            protocol: &NSURLProtocol,
47            cached_response: &NSCachedURLResponse,
48        );
49
50        #[cfg(all(feature = "NSURLCache", feature = "NSURLResponse"))]
51        /// Indicates to an NSURLProtocolClient that the protocol
52        /// implementation has created an NSURLResponse for the current load.
53        ///
54        /// Parameter `protocol`: the NSURLProtocol object sending the message.
55        ///
56        /// Parameter `response`: the NSURLResponse object the protocol implementation
57        /// has created.
58        ///
59        /// Parameter `policy`: The NSURLCacheStoragePolicy the protocol
60        /// has determined should be used for the given response if the
61        /// response is to be stored in a cache.
62        #[unsafe(method(URLProtocol:didReceiveResponse:cacheStoragePolicy:))]
63        #[unsafe(method_family = none)]
64        unsafe fn URLProtocol_didReceiveResponse_cacheStoragePolicy(
65            &self,
66            protocol: &NSURLProtocol,
67            response: &NSURLResponse,
68            policy: NSURLCacheStoragePolicy,
69        );
70
71        #[cfg(feature = "NSData")]
72        /// Indicates to an NSURLProtocolClient that the protocol
73        /// implementation has loaded URL data.
74        ///
75        /// The data object must contain only new data loaded since
76        /// the previous call to this method (if any), not cumulative data for
77        /// the entire load.
78        ///
79        /// Parameter `protocol`: the NSURLProtocol object sending the message.
80        ///
81        /// Parameter `data`: URL load data being made available.
82        #[unsafe(method(URLProtocol:didLoadData:))]
83        #[unsafe(method_family = none)]
84        unsafe fn URLProtocol_didLoadData(&self, protocol: &NSURLProtocol, data: &NSData);
85
86        /// Indicates to an NSURLProtocolClient that the protocol
87        /// implementation has finished loading successfully.
88        ///
89        /// Parameter `protocol`: the NSURLProtocol object sending the message.
90        #[unsafe(method(URLProtocolDidFinishLoading:))]
91        #[unsafe(method_family = none)]
92        unsafe fn URLProtocolDidFinishLoading(&self, protocol: &NSURLProtocol);
93
94        #[cfg(feature = "NSError")]
95        /// Indicates to an NSURLProtocolClient that the protocol
96        /// implementation has failed to load successfully.
97        ///
98        /// Parameter `protocol`: the NSURLProtocol object sending the message.
99        ///
100        /// Parameter `error`: The error that caused the load to fail.
101        #[unsafe(method(URLProtocol:didFailWithError:))]
102        #[unsafe(method_family = none)]
103        unsafe fn URLProtocol_didFailWithError(&self, protocol: &NSURLProtocol, error: &NSError);
104
105        #[cfg(feature = "NSURLAuthenticationChallenge")]
106        /// Start authentication for the specified request
107        ///
108        /// Parameter `protocol`: The protocol object requesting authentication.
109        ///
110        /// Parameter `challenge`: The authentication challenge.
111        ///
112        /// The protocol client guarantees that it will answer the
113        /// request on the same thread that called this method. It may add a
114        /// default credential to the challenge it issues to the connection delegate,
115        /// if the protocol did not provide one.
116        #[unsafe(method(URLProtocol:didReceiveAuthenticationChallenge:))]
117        #[unsafe(method_family = none)]
118        unsafe fn URLProtocol_didReceiveAuthenticationChallenge(
119            &self,
120            protocol: &NSURLProtocol,
121            challenge: &NSURLAuthenticationChallenge,
122        );
123
124        #[cfg(feature = "NSURLAuthenticationChallenge")]
125        /// Cancel authentication for the specified request
126        ///
127        /// Parameter `protocol`: The protocol object cancelling authentication.
128        ///
129        /// Parameter `challenge`: The authentication challenge.
130        #[unsafe(method(URLProtocol:didCancelAuthenticationChallenge:))]
131        #[unsafe(method_family = none)]
132        unsafe fn URLProtocol_didCancelAuthenticationChallenge(
133            &self,
134            protocol: &NSURLProtocol,
135            challenge: &NSURLAuthenticationChallenge,
136        );
137    }
138);
139
140extern_class!(
141    /// NSURLProtocol is an abstract class which provides the
142    /// basic structure for performing protocol-specific loading of URL
143    /// data. Concrete subclasses handle the specifics associated with one
144    /// or more protocols or URL schemes.
145    ///
146    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlprotocol?language=objc)
147    #[unsafe(super(NSObject))]
148    #[derive(Debug, PartialEq, Eq, Hash)]
149    pub struct NSURLProtocol;
150);
151
152unsafe impl NSObjectProtocol for NSURLProtocol {}
153
154impl NSURLProtocol {
155    extern_methods!(
156        #[cfg(all(feature = "NSURLCache", feature = "NSURLRequest"))]
157        /// Initializes an NSURLProtocol given request,
158        /// cached response, and client.
159        ///
160        /// Parameter `request`: The request to load.
161        ///
162        /// Parameter `cachedResponse`: A response that has been retrieved from the
163        /// cache for the given request. The protocol implementation should
164        /// apply protocol-specific validity checks if such tests are
165        /// necessary.
166        ///
167        /// Parameter `client`: The NSURLProtocolClient object that serves as the
168        /// interface the protocol implementation can use to report results back
169        /// to the URL loading system.
170        #[unsafe(method(initWithRequest:cachedResponse:client:))]
171        #[unsafe(method_family = init)]
172        pub unsafe fn initWithRequest_cachedResponse_client(
173            this: Allocated<Self>,
174            request: &NSURLRequest,
175            cached_response: Option<&NSCachedURLResponse>,
176            client: Option<&ProtocolObject<dyn NSURLProtocolClient>>,
177        ) -> Retained<Self>;
178
179        /// Returns the NSURLProtocolClient of the receiver.
180        ///
181        /// Returns: The NSURLProtocolClient of the receiver.
182        #[unsafe(method(client))]
183        #[unsafe(method_family = none)]
184        pub unsafe fn client(&self) -> Option<Retained<ProtocolObject<dyn NSURLProtocolClient>>>;
185
186        #[cfg(feature = "NSURLRequest")]
187        /// Returns the NSURLRequest of the receiver.
188        ///
189        /// Returns: The NSURLRequest of the receiver.
190        #[unsafe(method(request))]
191        #[unsafe(method_family = none)]
192        pub unsafe fn request(&self) -> Retained<NSURLRequest>;
193
194        #[cfg(feature = "NSURLCache")]
195        /// Returns the NSCachedURLResponse of the receiver.
196        ///
197        /// Returns: The NSCachedURLResponse of the receiver.
198        #[unsafe(method(cachedResponse))]
199        #[unsafe(method_family = none)]
200        pub unsafe fn cachedResponse(&self) -> Option<Retained<NSCachedURLResponse>>;
201
202        #[cfg(feature = "NSURLRequest")]
203        /// This method determines whether this protocol can handle
204        /// the given request.
205        ///
206        /// A concrete subclass should inspect the given request and
207        /// determine whether or not the implementation can perform a load with
208        /// that request. This is an abstract method. Subclasses must provide an
209        /// implementation.
210        ///
211        /// Parameter `request`: A request to inspect.
212        ///
213        /// Returns: YES if the protocol can handle the given request, NO if not.
214        #[unsafe(method(canInitWithRequest:))]
215        #[unsafe(method_family = none)]
216        pub unsafe fn canInitWithRequest(request: &NSURLRequest) -> bool;
217
218        #[cfg(feature = "NSURLRequest")]
219        /// This method returns a canonical version of the given
220        /// request.
221        ///
222        /// It is up to each concrete protocol implementation to
223        /// define what "canonical" means. However, a protocol should
224        /// guarantee that the same input request always yields the same
225        /// canonical form. Special consideration should be given when
226        /// implementing this method since the canonical form of a request is
227        /// used to look up objects in the URL cache, a process which performs
228        /// equality checks between NSURLRequest objects.
229        /// <p>
230        /// This is an abstract method; subclasses must provide an
231        /// implementation.
232        ///
233        /// Parameter `request`: A request to make canonical.
234        ///
235        /// Returns: The canonical form of the given request.
236        #[unsafe(method(canonicalRequestForRequest:))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn canonicalRequestForRequest(request: &NSURLRequest) -> Retained<NSURLRequest>;
239
240        #[cfg(feature = "NSURLRequest")]
241        /// Compares two requests for equivalence with regard to caching.
242        ///
243        /// Requests are considered equivalent for cache purposes
244        /// if and only if they would be handled by the same protocol AND that
245        /// protocol declares them equivalent after performing
246        /// implementation-specific checks.
247        ///
248        /// Returns: YES if the two requests are cache-equivalent, NO otherwise.
249        #[unsafe(method(requestIsCacheEquivalent:toRequest:))]
250        #[unsafe(method_family = none)]
251        pub unsafe fn requestIsCacheEquivalent_toRequest(
252            a: &NSURLRequest,
253            b: &NSURLRequest,
254        ) -> bool;
255
256        /// Starts protocol-specific loading of a request.
257        ///
258        /// When this method is called, the protocol implementation
259        /// should start loading a request.
260        #[unsafe(method(startLoading))]
261        #[unsafe(method_family = none)]
262        pub unsafe fn startLoading(&self);
263
264        /// Stops protocol-specific loading of a request.
265        ///
266        /// When this method is called, the protocol implementation
267        /// should end the work of loading a request. This could be in response
268        /// to a cancel operation, so protocol implementations must be able to
269        /// handle this call while a load is in progress.
270        #[unsafe(method(stopLoading))]
271        #[unsafe(method_family = none)]
272        pub unsafe fn stopLoading(&self);
273
274        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
275        /// Returns the property in the given request previously
276        /// stored with the given key.
277        ///
278        /// The purpose of this method is to provide an interface
279        /// for protocol implementors to access protocol-specific information
280        /// associated with NSURLRequest objects.
281        ///
282        /// Parameter `key`: The string to use for the property lookup.
283        ///
284        /// Parameter `request`: The request to use for the property lookup.
285        ///
286        /// Returns: The property stored with the given key, or nil if no property
287        /// had previously been stored with the given key in the given request.
288        #[unsafe(method(propertyForKey:inRequest:))]
289        #[unsafe(method_family = none)]
290        pub unsafe fn propertyForKey_inRequest(
291            key: &NSString,
292            request: &NSURLRequest,
293        ) -> Option<Retained<AnyObject>>;
294
295        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
296        /// Stores the given property in the given request using the
297        /// given key.
298        ///
299        /// The purpose of this method is to provide an interface
300        /// for protocol implementors to customize protocol-specific
301        /// information associated with NSMutableURLRequest objects.
302        ///
303        /// Parameter `value`: The property to store.
304        ///
305        /// Parameter `key`: The string to use for the property storage.
306        ///
307        /// Parameter `request`: The request in which to store the property.
308        #[unsafe(method(setProperty:forKey:inRequest:))]
309        #[unsafe(method_family = none)]
310        pub unsafe fn setProperty_forKey_inRequest(
311            value: &AnyObject,
312            key: &NSString,
313            request: &NSMutableURLRequest,
314        );
315
316        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
317        /// Remove any property stored under the given key
318        ///
319        /// Like setProperty:forKey:inRequest: above, the purpose of this
320        /// method is to give protocol implementors the ability to store
321        /// protocol-specific information in an NSURLRequest
322        ///
323        /// Parameter `key`: The key whose value should be removed
324        ///
325        /// Parameter `request`: The request to be modified
326        #[unsafe(method(removePropertyForKey:inRequest:))]
327        #[unsafe(method_family = none)]
328        pub unsafe fn removePropertyForKey_inRequest(key: &NSString, request: &NSMutableURLRequest);
329
330        /// This method registers a protocol class, making it visible
331        /// to several other NSURLProtocol class methods.
332        ///
333        /// When the URL loading system begins to load a request,
334        /// each protocol class that has been registered is consulted in turn to
335        /// see if it can be initialized with a given request. The first
336        /// protocol handler class to provide a YES answer to
337        /// <tt>
338        /// +canInitWithRequest:
339        /// </tt>
340        /// "wins" and that protocol
341        /// implementation is used to perform the URL load. There is no
342        /// guarantee that all registered protocol classes will be consulted.
343        /// Hence, it should be noted that registering a class places it first
344        /// on the list of classes that will be consulted in calls to
345        /// <tt>
346        /// +canInitWithRequest:
347        /// </tt>
348        /// , moving it in front of all classes
349        /// that had been registered previously.
350        /// <p>
351        /// A similar design governs the process to create the canonical form
352        /// of a request with the
353        /// <tt>
354        /// +canonicalRequestForRequest:
355        /// </tt>
356        /// class
357        /// method.
358        ///
359        /// Parameter `protocolClass`: the class to register.
360        ///
361        /// Returns: YES if the protocol was registered successfully, NO if not.
362        /// The only way that failure can occur is if the given class is not a
363        /// subclass of NSURLProtocol.
364        #[unsafe(method(registerClass:))]
365        #[unsafe(method_family = none)]
366        pub unsafe fn registerClass(protocol_class: &AnyClass) -> bool;
367
368        /// This method unregisters a protocol.
369        ///
370        /// After unregistration, a protocol class is no longer
371        /// consulted in calls to NSURLProtocol class methods.
372        ///
373        /// Parameter `protocolClass`: The class to unregister.
374        #[unsafe(method(unregisterClass:))]
375        #[unsafe(method_family = none)]
376        pub unsafe fn unregisterClass(protocol_class: &AnyClass);
377    );
378}
379
380/// Methods declared on superclass `NSObject`.
381impl NSURLProtocol {
382    extern_methods!(
383        #[unsafe(method(init))]
384        #[unsafe(method_family = init)]
385        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
386
387        #[unsafe(method(new))]
388        #[unsafe(method_family = new)]
389        pub unsafe fn new() -> Retained<Self>;
390    );
391}
392
393/// NSURLSessionTaskAdditions.
394impl NSURLProtocol {
395    extern_methods!(
396        #[cfg(feature = "NSURLSession")]
397        #[unsafe(method(canInitWithTask:))]
398        #[unsafe(method_family = none)]
399        pub unsafe fn canInitWithTask(task: &NSURLSessionTask) -> bool;
400
401        #[cfg(all(feature = "NSURLCache", feature = "NSURLSession"))]
402        #[unsafe(method(initWithTask:cachedResponse:client:))]
403        #[unsafe(method_family = init)]
404        pub unsafe fn initWithTask_cachedResponse_client(
405            this: Allocated<Self>,
406            task: &NSURLSessionTask,
407            cached_response: Option<&NSCachedURLResponse>,
408            client: Option<&ProtocolObject<dyn NSURLProtocolClient>>,
409        ) -> Retained<Self>;
410
411        #[cfg(feature = "NSURLSession")]
412        #[unsafe(method(task))]
413        #[unsafe(method_family = none)]
414        pub unsafe fn task(&self) -> Option<Retained<NSURLSessionTask>>;
415    );
416}