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 + Send + Sync {
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 fn requestIsCacheEquivalent_toRequest(a: &NSURLRequest, b: &NSURLRequest) -> bool;
254
255 /// Starts protocol-specific loading of a request.
256 ///
257 /// When this method is called, the protocol implementation
258 /// should start loading a request.
259 #[unsafe(method(startLoading))]
260 #[unsafe(method_family = none)]
261 pub fn startLoading(&self);
262
263 /// Stops protocol-specific loading of a request.
264 ///
265 /// When this method is called, the protocol implementation
266 /// should end the work of loading a request. This could be in response
267 /// to a cancel operation, so protocol implementations must be able to
268 /// handle this call while a load is in progress.
269 #[unsafe(method(stopLoading))]
270 #[unsafe(method_family = none)]
271 pub fn stopLoading(&self);
272
273 #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
274 /// Returns the property in the given request previously
275 /// stored with the given key.
276 ///
277 /// The purpose of this method is to provide an interface
278 /// for protocol implementors to access protocol-specific information
279 /// associated with NSURLRequest objects.
280 ///
281 /// Parameter `key`: The string to use for the property lookup.
282 ///
283 /// Parameter `request`: The request to use for the property lookup.
284 ///
285 /// Returns: The property stored with the given key, or nil if no property
286 /// had previously been stored with the given key in the given request.
287 #[unsafe(method(propertyForKey:inRequest:))]
288 #[unsafe(method_family = none)]
289 pub fn propertyForKey_inRequest(
290 key: &NSString,
291 request: &NSURLRequest,
292 ) -> Option<Retained<AnyObject>>;
293
294 #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
295 /// Stores the given property in the given request using the
296 /// given key.
297 ///
298 /// The purpose of this method is to provide an interface
299 /// for protocol implementors to customize protocol-specific
300 /// information associated with NSMutableURLRequest objects.
301 ///
302 /// Parameter `value`: The property to store.
303 ///
304 /// Parameter `key`: The string to use for the property storage.
305 ///
306 /// Parameter `request`: The request in which to store the property.
307 ///
308 /// # Safety
309 ///
310 /// `value` should be of the correct type.
311 #[unsafe(method(setProperty:forKey:inRequest:))]
312 #[unsafe(method_family = none)]
313 pub unsafe fn setProperty_forKey_inRequest(
314 value: &AnyObject,
315 key: &NSString,
316 request: &NSMutableURLRequest,
317 );
318
319 #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
320 /// Remove any property stored under the given key
321 ///
322 /// Like setProperty:forKey:inRequest: above, the purpose of this
323 /// method is to give protocol implementors the ability to store
324 /// protocol-specific information in an NSURLRequest
325 ///
326 /// Parameter `key`: The key whose value should be removed
327 ///
328 /// Parameter `request`: The request to be modified
329 #[unsafe(method(removePropertyForKey:inRequest:))]
330 #[unsafe(method_family = none)]
331 pub fn removePropertyForKey_inRequest(key: &NSString, request: &NSMutableURLRequest);
332
333 /// This method registers a protocol class, making it visible
334 /// to several other NSURLProtocol class methods.
335 ///
336 /// When the URL loading system begins to load a request,
337 /// each protocol class that has been registered is consulted in turn to
338 /// see if it can be initialized with a given request. The first
339 /// protocol handler class to provide a YES answer to
340 /// <tt>
341 /// +canInitWithRequest:
342 /// </tt>
343 /// "wins" and that protocol
344 /// implementation is used to perform the URL load. There is no
345 /// guarantee that all registered protocol classes will be consulted.
346 /// Hence, it should be noted that registering a class places it first
347 /// on the list of classes that will be consulted in calls to
348 /// <tt>
349 /// +canInitWithRequest:
350 /// </tt>
351 /// , moving it in front of all classes
352 /// that had been registered previously.
353 /// <p>
354 /// A similar design governs the process to create the canonical form
355 /// of a request with the
356 /// <tt>
357 /// +canonicalRequestForRequest:
358 /// </tt>
359 /// class
360 /// method.
361 ///
362 /// Parameter `protocolClass`: the class to register.
363 ///
364 /// Returns: YES if the protocol was registered successfully, NO if not.
365 /// The only way that failure can occur is if the given class is not a
366 /// subclass of NSURLProtocol.
367 ///
368 /// # Safety
369 ///
370 /// `protocol_class` probably has further requirements.
371 #[unsafe(method(registerClass:))]
372 #[unsafe(method_family = none)]
373 pub unsafe fn registerClass(protocol_class: &AnyClass) -> bool;
374
375 /// This method unregisters a protocol.
376 ///
377 /// After unregistration, a protocol class is no longer
378 /// consulted in calls to NSURLProtocol class methods.
379 ///
380 /// Parameter `protocolClass`: The class to unregister.
381 ///
382 /// # Safety
383 ///
384 /// `protocol_class` probably has further requirements.
385 #[unsafe(method(unregisterClass:))]
386 #[unsafe(method_family = none)]
387 pub unsafe fn unregisterClass(protocol_class: &AnyClass);
388 );
389}
390
391/// Methods declared on superclass `NSObject`.
392impl NSURLProtocol {
393 extern_methods!(
394 #[unsafe(method(init))]
395 #[unsafe(method_family = init)]
396 pub fn init(this: Allocated<Self>) -> Retained<Self>;
397
398 #[unsafe(method(new))]
399 #[unsafe(method_family = new)]
400 pub fn new() -> Retained<Self>;
401 );
402}
403
404impl DefaultRetained for NSURLProtocol {
405 #[inline]
406 fn default_retained() -> Retained<Self> {
407 Self::new()
408 }
409}
410
411/// NSURLSessionTaskAdditions.
412impl NSURLProtocol {
413 extern_methods!(
414 #[cfg(feature = "NSURLSession")]
415 #[unsafe(method(canInitWithTask:))]
416 #[unsafe(method_family = none)]
417 pub fn canInitWithTask(task: &NSURLSessionTask) -> bool;
418
419 #[cfg(all(feature = "NSURLCache", feature = "NSURLSession"))]
420 #[unsafe(method(initWithTask:cachedResponse:client:))]
421 #[unsafe(method_family = init)]
422 pub fn initWithTask_cachedResponse_client(
423 this: Allocated<Self>,
424 task: &NSURLSessionTask,
425 cached_response: Option<&NSCachedURLResponse>,
426 client: Option<&ProtocolObject<dyn NSURLProtocolClient>>,
427 ) -> Retained<Self>;
428
429 #[cfg(feature = "NSURLSession")]
430 #[unsafe(method(task))]
431 #[unsafe(method_family = none)]
432 pub fn task(&self) -> Option<Retained<NSURLSessionTask>>;
433 );
434}