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
152extern_conformance!(
153    unsafe impl NSObjectProtocol for NSURLProtocol {}
154);
155
156impl NSURLProtocol {
157    extern_methods!(
158        #[cfg(all(feature = "NSURLCache", feature = "NSURLRequest"))]
159        /// Initializes an NSURLProtocol given request,
160        /// cached response, and client.
161        ///
162        /// Parameter `request`: The request to load.
163        ///
164        /// Parameter `cachedResponse`: A response that has been retrieved from the
165        /// cache for the given request. The protocol implementation should
166        /// apply protocol-specific validity checks if such tests are
167        /// necessary.
168        ///
169        /// Parameter `client`: The NSURLProtocolClient object that serves as the
170        /// interface the protocol implementation can use to report results back
171        /// to the URL loading system.
172        #[unsafe(method(initWithRequest:cachedResponse:client:))]
173        #[unsafe(method_family = init)]
174        pub unsafe fn initWithRequest_cachedResponse_client(
175            this: Allocated<Self>,
176            request: &NSURLRequest,
177            cached_response: Option<&NSCachedURLResponse>,
178            client: Option<&ProtocolObject<dyn NSURLProtocolClient>>,
179        ) -> Retained<Self>;
180
181        /// Returns the NSURLProtocolClient of the receiver.
182        ///
183        /// Returns: The NSURLProtocolClient of the receiver.
184        #[unsafe(method(client))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn client(&self) -> Option<Retained<ProtocolObject<dyn NSURLProtocolClient>>>;
187
188        #[cfg(feature = "NSURLRequest")]
189        /// Returns the NSURLRequest of the receiver.
190        ///
191        /// Returns: The NSURLRequest of the receiver.
192        #[unsafe(method(request))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn request(&self) -> Retained<NSURLRequest>;
195
196        #[cfg(feature = "NSURLCache")]
197        /// Returns the NSCachedURLResponse of the receiver.
198        ///
199        /// Returns: The NSCachedURLResponse of the receiver.
200        #[unsafe(method(cachedResponse))]
201        #[unsafe(method_family = none)]
202        pub unsafe fn cachedResponse(&self) -> Option<Retained<NSCachedURLResponse>>;
203
204        #[cfg(feature = "NSURLRequest")]
205        /// This method determines whether this protocol can handle
206        /// the given request.
207        ///
208        /// A concrete subclass should inspect the given request and
209        /// determine whether or not the implementation can perform a load with
210        /// that request. This is an abstract method. Subclasses must provide an
211        /// implementation.
212        ///
213        /// Parameter `request`: A request to inspect.
214        ///
215        /// Returns: YES if the protocol can handle the given request, NO if not.
216        #[unsafe(method(canInitWithRequest:))]
217        #[unsafe(method_family = none)]
218        pub unsafe fn canInitWithRequest(request: &NSURLRequest) -> bool;
219
220        #[cfg(feature = "NSURLRequest")]
221        /// This method returns a canonical version of the given
222        /// request.
223        ///
224        /// It is up to each concrete protocol implementation to
225        /// define what "canonical" means. However, a protocol should
226        /// guarantee that the same input request always yields the same
227        /// canonical form. Special consideration should be given when
228        /// implementing this method since the canonical form of a request is
229        /// used to look up objects in the URL cache, a process which performs
230        /// equality checks between NSURLRequest objects.
231        /// <p>
232        /// This is an abstract method; subclasses must provide an
233        /// implementation.
234        ///
235        /// Parameter `request`: A request to make canonical.
236        ///
237        /// Returns: The canonical form of the given request.
238        #[unsafe(method(canonicalRequestForRequest:))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn canonicalRequestForRequest(request: &NSURLRequest) -> Retained<NSURLRequest>;
241
242        #[cfg(feature = "NSURLRequest")]
243        /// Compares two requests for equivalence with regard to caching.
244        ///
245        /// Requests are considered equivalent for cache purposes
246        /// if and only if they would be handled by the same protocol AND that
247        /// protocol declares them equivalent after performing
248        /// implementation-specific checks.
249        ///
250        /// Returns: YES if the two requests are cache-equivalent, NO otherwise.
251        #[unsafe(method(requestIsCacheEquivalent:toRequest:))]
252        #[unsafe(method_family = none)]
253        pub unsafe fn requestIsCacheEquivalent_toRequest(
254            a: &NSURLRequest,
255            b: &NSURLRequest,
256        ) -> bool;
257
258        /// Starts protocol-specific loading of a request.
259        ///
260        /// When this method is called, the protocol implementation
261        /// should start loading a request.
262        #[unsafe(method(startLoading))]
263        #[unsafe(method_family = none)]
264        pub unsafe fn startLoading(&self);
265
266        /// Stops protocol-specific loading of a request.
267        ///
268        /// When this method is called, the protocol implementation
269        /// should end the work of loading a request. This could be in response
270        /// to a cancel operation, so protocol implementations must be able to
271        /// handle this call while a load is in progress.
272        #[unsafe(method(stopLoading))]
273        #[unsafe(method_family = none)]
274        pub unsafe fn stopLoading(&self);
275
276        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
277        /// Returns the property in the given request previously
278        /// stored with the given key.
279        ///
280        /// The purpose of this method is to provide an interface
281        /// for protocol implementors to access protocol-specific information
282        /// associated with NSURLRequest objects.
283        ///
284        /// Parameter `key`: The string to use for the property lookup.
285        ///
286        /// Parameter `request`: The request to use for the property lookup.
287        ///
288        /// Returns: The property stored with the given key, or nil if no property
289        /// had previously been stored with the given key in the given request.
290        #[unsafe(method(propertyForKey:inRequest:))]
291        #[unsafe(method_family = none)]
292        pub unsafe fn propertyForKey_inRequest(
293            key: &NSString,
294            request: &NSURLRequest,
295        ) -> Option<Retained<AnyObject>>;
296
297        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
298        /// Stores the given property in the given request using the
299        /// given key.
300        ///
301        /// The purpose of this method is to provide an interface
302        /// for protocol implementors to customize protocol-specific
303        /// information associated with NSMutableURLRequest objects.
304        ///
305        /// Parameter `value`: The property to store.
306        ///
307        /// Parameter `key`: The string to use for the property storage.
308        ///
309        /// Parameter `request`: The request in which to store the property.
310        #[unsafe(method(setProperty:forKey:inRequest:))]
311        #[unsafe(method_family = none)]
312        pub unsafe fn setProperty_forKey_inRequest(
313            value: &AnyObject,
314            key: &NSString,
315            request: &NSMutableURLRequest,
316        );
317
318        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
319        /// Remove any property stored under the given key
320        ///
321        /// Like setProperty:forKey:inRequest: above, the purpose of this
322        /// method is to give protocol implementors the ability to store
323        /// protocol-specific information in an NSURLRequest
324        ///
325        /// Parameter `key`: The key whose value should be removed
326        ///
327        /// Parameter `request`: The request to be modified
328        #[unsafe(method(removePropertyForKey:inRequest:))]
329        #[unsafe(method_family = none)]
330        pub unsafe fn removePropertyForKey_inRequest(key: &NSString, request: &NSMutableURLRequest);
331
332        /// This method registers a protocol class, making it visible
333        /// to several other NSURLProtocol class methods.
334        ///
335        /// When the URL loading system begins to load a request,
336        /// each protocol class that has been registered is consulted in turn to
337        /// see if it can be initialized with a given request. The first
338        /// protocol handler class to provide a YES answer to
339        /// <tt>
340        /// +canInitWithRequest:
341        /// </tt>
342        /// "wins" and that protocol
343        /// implementation is used to perform the URL load. There is no
344        /// guarantee that all registered protocol classes will be consulted.
345        /// Hence, it should be noted that registering a class places it first
346        /// on the list of classes that will be consulted in calls to
347        /// <tt>
348        /// +canInitWithRequest:
349        /// </tt>
350        /// , moving it in front of all classes
351        /// that had been registered previously.
352        /// <p>
353        /// A similar design governs the process to create the canonical form
354        /// of a request with the
355        /// <tt>
356        /// +canonicalRequestForRequest:
357        /// </tt>
358        /// class
359        /// method.
360        ///
361        /// Parameter `protocolClass`: the class to register.
362        ///
363        /// Returns: YES if the protocol was registered successfully, NO if not.
364        /// The only way that failure can occur is if the given class is not a
365        /// subclass of NSURLProtocol.
366        #[unsafe(method(registerClass:))]
367        #[unsafe(method_family = none)]
368        pub unsafe fn registerClass(protocol_class: &AnyClass) -> bool;
369
370        /// This method unregisters a protocol.
371        ///
372        /// After unregistration, a protocol class is no longer
373        /// consulted in calls to NSURLProtocol class methods.
374        ///
375        /// Parameter `protocolClass`: The class to unregister.
376        #[unsafe(method(unregisterClass:))]
377        #[unsafe(method_family = none)]
378        pub unsafe fn unregisterClass(protocol_class: &AnyClass);
379    );
380}
381
382/// Methods declared on superclass `NSObject`.
383impl NSURLProtocol {
384    extern_methods!(
385        #[unsafe(method(init))]
386        #[unsafe(method_family = init)]
387        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
388
389        #[unsafe(method(new))]
390        #[unsafe(method_family = new)]
391        pub unsafe fn new() -> Retained<Self>;
392    );
393}
394
395/// NSURLSessionTaskAdditions.
396impl NSURLProtocol {
397    extern_methods!(
398        #[cfg(feature = "NSURLSession")]
399        #[unsafe(method(canInitWithTask:))]
400        #[unsafe(method_family = none)]
401        pub unsafe fn canInitWithTask(task: &NSURLSessionTask) -> bool;
402
403        #[cfg(all(feature = "NSURLCache", feature = "NSURLSession"))]
404        #[unsafe(method(initWithTask:cachedResponse:client:))]
405        #[unsafe(method_family = init)]
406        pub unsafe fn initWithTask_cachedResponse_client(
407            this: Allocated<Self>,
408            task: &NSURLSessionTask,
409            cached_response: Option<&NSCachedURLResponse>,
410            client: Option<&ProtocolObject<dyn NSURLProtocolClient>>,
411        ) -> Retained<Self>;
412
413        #[cfg(feature = "NSURLSession")]
414        #[unsafe(method(task))]
415        #[unsafe(method_family = none)]
416        pub unsafe fn task(&self) -> Option<Retained<NSURLSessionTask>>;
417    );
418}