objc2_foundation/generated/NSURLRequest.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
9/// The NSURLRequestCachePolicy enum defines constants that
10/// can be used to specify the type of interactions that take place with
11/// the caching system when the URL loading system processes a request.
12/// Specifically, these constants cover interactions that have to do
13/// with whether already-existing cache data is returned to satisfy a
14/// URL load request.
15///
16///
17/// caching logic defined in the protocol implementation, if any, is
18/// used for a particular URL load request. This is the default policy
19/// for URL load requests.
20///
21///
22/// data for the URL load should be loaded from the origin source. No
23/// existing local cache data, regardless of its freshness or validity,
24/// should be used to satisfy a URL load request.
25///
26///
27/// not only should the local cache data be ignored, but that proxies and
28/// other intermediates should be instructed to disregard their caches
29/// so far as the protocol allows.
30///
31///
32/// NSURLRequestReloadIgnoringLocalCacheData.
33///
34///
35/// existing cache data should be used to satisfy a URL load request,
36/// regardless of its age or expiration date. However, if there is no
37/// existing data in the cache corresponding to a URL load request,
38/// the URL is loaded from the origin source.
39///
40///
41/// existing cache data should be used to satisfy a URL load request,
42/// regardless of its age or expiration date. However, if there is no
43/// existing data in the cache corresponding to a URL load request, no
44/// attempt is made to load the URL from the origin source, and the
45/// load is considered to have failed. This constant specifies a
46/// behavior that is similar to an "offline" mode.
47///
48///
49/// the existing cache data may be used provided the origin source
50/// confirms its validity, otherwise the URL is loaded from the
51/// origin source.
52///
53/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlrequestcachepolicy?language=objc)
54// NS_ENUM
55#[repr(transparent)]
56#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
57pub struct NSURLRequestCachePolicy(pub NSUInteger);
58impl NSURLRequestCachePolicy {
59 #[doc(alias = "NSURLRequestUseProtocolCachePolicy")]
60 pub const UseProtocolCachePolicy: Self = Self(0);
61 #[doc(alias = "NSURLRequestReloadIgnoringLocalCacheData")]
62 pub const ReloadIgnoringLocalCacheData: Self = Self(1);
63 #[doc(alias = "NSURLRequestReloadIgnoringLocalAndRemoteCacheData")]
64 pub const ReloadIgnoringLocalAndRemoteCacheData: Self = Self(4);
65 #[doc(alias = "NSURLRequestReloadIgnoringCacheData")]
66 pub const ReloadIgnoringCacheData: Self =
67 Self(NSURLRequestCachePolicy::ReloadIgnoringLocalCacheData.0);
68 #[doc(alias = "NSURLRequestReturnCacheDataElseLoad")]
69 pub const ReturnCacheDataElseLoad: Self = Self(2);
70 #[doc(alias = "NSURLRequestReturnCacheDataDontLoad")]
71 pub const ReturnCacheDataDontLoad: Self = Self(3);
72 #[doc(alias = "NSURLRequestReloadRevalidatingCacheData")]
73 pub const ReloadRevalidatingCacheData: Self = Self(5);
74}
75
76unsafe impl Encode for NSURLRequestCachePolicy {
77 const ENCODING: Encoding = NSUInteger::ENCODING;
78}
79
80unsafe impl RefEncode for NSURLRequestCachePolicy {
81 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
82}
83
84/// The NSURLRequestNetworkServiceType enum defines constants that
85/// can be used to specify the service type to associate with this request. The
86/// service type is used to provide the networking layers a hint of the purpose
87/// of the request.
88///
89///
90/// when created. This value should be left unchanged for the vast majority of requests.
91///
92///
93/// control traffic.
94///
95///
96/// traffic.
97///
98///
99/// traffic (such as a file download).
100///
101/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlrequestnetworkservicetype?language=objc)
102// NS_ENUM
103#[repr(transparent)]
104#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
105pub struct NSURLRequestNetworkServiceType(pub NSUInteger);
106impl NSURLRequestNetworkServiceType {
107 #[doc(alias = "NSURLNetworkServiceTypeDefault")]
108 pub const NetworkServiceTypeDefault: Self = Self(0);
109 #[doc(alias = "NSURLNetworkServiceTypeVoIP")]
110 #[deprecated = "Use PushKit for VoIP control purposes"]
111 pub const NetworkServiceTypeVoIP: Self = Self(1);
112 #[doc(alias = "NSURLNetworkServiceTypeVideo")]
113 pub const NetworkServiceTypeVideo: Self = Self(2);
114 #[doc(alias = "NSURLNetworkServiceTypeBackground")]
115 pub const NetworkServiceTypeBackground: Self = Self(3);
116 #[doc(alias = "NSURLNetworkServiceTypeVoice")]
117 pub const NetworkServiceTypeVoice: Self = Self(4);
118 #[doc(alias = "NSURLNetworkServiceTypeResponsiveData")]
119 pub const NetworkServiceTypeResponsiveData: Self = Self(6);
120 #[doc(alias = "NSURLNetworkServiceTypeAVStreaming")]
121 pub const NetworkServiceTypeAVStreaming: Self = Self(8);
122 #[doc(alias = "NSURLNetworkServiceTypeResponsiveAV")]
123 pub const NetworkServiceTypeResponsiveAV: Self = Self(9);
124 #[doc(alias = "NSURLNetworkServiceTypeCallSignaling")]
125 pub const NetworkServiceTypeCallSignaling: Self = Self(11);
126}
127
128unsafe impl Encode for NSURLRequestNetworkServiceType {
129 const ENCODING: Encoding = NSUInteger::ENCODING;
130}
131
132unsafe impl RefEncode for NSURLRequestNetworkServiceType {
133 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
134}
135
136/// The NSURLRequestAttribution enum is used to indicate whether the
137/// user or developer specified the URL.
138///
139///
140/// by the developer. This is the default value for an NSURLRequest when created.
141///
142///
143/// the user.
144///
145/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlrequestattribution?language=objc)
146// NS_ENUM
147#[repr(transparent)]
148#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
149pub struct NSURLRequestAttribution(pub NSUInteger);
150impl NSURLRequestAttribution {
151 #[doc(alias = "NSURLRequestAttributionDeveloper")]
152 pub const Developer: Self = Self(0);
153 #[doc(alias = "NSURLRequestAttributionUser")]
154 pub const User: Self = Self(1);
155}
156
157unsafe impl Encode for NSURLRequestAttribution {
158 const ENCODING: Encoding = NSUInteger::ENCODING;
159}
160
161unsafe impl RefEncode for NSURLRequestAttribution {
162 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
163}
164
165extern_class!(
166 /// An NSURLRequest object represents a URL load request in a
167 /// manner independent of protocol and URL scheme.
168 ///
169 ///
170 /// NSURLRequest encapsulates two basic data elements about
171 /// a URL load request:
172 /// <ul>
173 /// <li>
174 /// The URL to load.
175 /// <li>
176 /// The policy to use when consulting the URL content cache made
177 /// available by the implementation.
178 /// </ul>
179 /// In addition, NSURLRequest is designed to be extended to support
180 /// protocol-specific data by adding categories to access a property
181 /// object provided in an interface targeted at protocol implementors.
182 /// <ul>
183 /// <li>
184 /// Protocol implementors should direct their attention to the
185 /// NSURLRequestExtensibility category on NSURLRequest for more
186 /// information on how to provide extensions on NSURLRequest to
187 /// support protocol-specific request information.
188 /// <li>
189 /// Clients of this API who wish to create NSURLRequest objects to
190 /// load URL content should consult the protocol-specific NSURLRequest
191 /// categories that are available. The NSHTTPURLRequest category on
192 /// NSURLRequest is an example.
193 /// </ul>
194 /// <p>
195 /// Objects of this class are used to create NSURLConnection instances,
196 /// which can are used to perform the load of a URL, or as input to the
197 /// NSURLConnection class method which performs synchronous loads.
198 ///
199 /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlrequest?language=objc)
200 #[unsafe(super(NSObject))]
201 #[derive(Debug, PartialEq, Eq, Hash)]
202 pub struct NSURLRequest;
203);
204
205#[cfg(feature = "NSObject")]
206extern_conformance!(
207 unsafe impl NSCoding for NSURLRequest {}
208);
209
210#[cfg(feature = "NSObject")]
211extern_conformance!(
212 unsafe impl NSCopying for NSURLRequest {}
213);
214
215#[cfg(feature = "NSObject")]
216unsafe impl CopyingHelper for NSURLRequest {
217 type Result = Self;
218}
219
220#[cfg(feature = "NSObject")]
221extern_conformance!(
222 unsafe impl NSMutableCopying for NSURLRequest {}
223);
224
225#[cfg(feature = "NSObject")]
226unsafe impl MutableCopyingHelper for NSURLRequest {
227 type Result = NSMutableURLRequest;
228}
229
230extern_conformance!(
231 unsafe impl NSObjectProtocol for NSURLRequest {}
232);
233
234#[cfg(feature = "NSObject")]
235extern_conformance!(
236 unsafe impl NSSecureCoding for NSURLRequest {}
237);
238
239impl NSURLRequest {
240 extern_methods!(
241 #[cfg(feature = "NSURL")]
242 /// Allocates and initializes an NSURLRequest with the given
243 /// URL.
244 ///
245 /// Default values are used for cache policy
246 /// (NSURLRequestUseProtocolCachePolicy) and timeout interval (60
247 /// seconds).
248 ///
249 /// Parameter `URL`: The URL for the request.
250 ///
251 /// Returns: A newly-created and autoreleased NSURLRequest instance.
252 #[unsafe(method(requestWithURL:))]
253 #[unsafe(method_family = none)]
254 pub fn requestWithURL(url: &NSURL) -> Retained<Self>;
255
256 /// Indicates that NSURLRequest implements the NSSecureCoding protocol.
257 ///
258 /// Returns: A BOOL value set to YES.
259 #[unsafe(method(supportsSecureCoding))]
260 #[unsafe(method_family = none)]
261 pub fn supportsSecureCoding() -> bool;
262
263 #[cfg(all(feature = "NSDate", feature = "NSURL"))]
264 /// Allocates and initializes a NSURLRequest with the given
265 /// URL and cache policy.
266 ///
267 /// Parameter `URL`: The URL for the request.
268 ///
269 /// Parameter `cachePolicy`: The cache policy for the request.
270 ///
271 /// Parameter `timeoutInterval`: The timeout interval for the request. See the
272 /// commentary for the
273 /// <tt>
274 /// timeoutInterval
275 /// </tt>
276 /// for more information on
277 /// timeout intervals.
278 ///
279 /// Returns: A newly-created and autoreleased NSURLRequest instance.
280 #[unsafe(method(requestWithURL:cachePolicy:timeoutInterval:))]
281 #[unsafe(method_family = none)]
282 pub fn requestWithURL_cachePolicy_timeoutInterval(
283 url: &NSURL,
284 cache_policy: NSURLRequestCachePolicy,
285 timeout_interval: NSTimeInterval,
286 ) -> Retained<Self>;
287
288 #[cfg(feature = "NSURL")]
289 /// Initializes an NSURLRequest with the given URL.
290 ///
291 /// Default values are used for cache policy
292 /// (NSURLRequestUseProtocolCachePolicy) and timeout interval (60
293 /// seconds).
294 ///
295 /// Parameter `URL`: The URL for the request.
296 ///
297 /// Returns: An initialized NSURLRequest.
298 #[unsafe(method(initWithURL:))]
299 #[unsafe(method_family = init)]
300 pub fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>;
301
302 #[cfg(all(feature = "NSDate", feature = "NSURL"))]
303 /// Initializes an NSURLRequest with the given URL and
304 /// cache policy.
305 ///
306 /// This is the designated initializer for the
307 /// NSURLRequest class.
308 ///
309 /// Parameter `URL`: The URL for the request.
310 ///
311 /// Parameter `cachePolicy`: The cache policy for the request.
312 ///
313 /// Parameter `timeoutInterval`: The timeout interval for the request. See the
314 /// commentary for the
315 /// <tt>
316 /// timeoutInterval
317 /// </tt>
318 /// for more information on
319 /// timeout intervals.
320 ///
321 /// Returns: An initialized NSURLRequest.
322 #[unsafe(method(initWithURL:cachePolicy:timeoutInterval:))]
323 #[unsafe(method_family = init)]
324 pub fn initWithURL_cachePolicy_timeoutInterval(
325 this: Allocated<Self>,
326 url: &NSURL,
327 cache_policy: NSURLRequestCachePolicy,
328 timeout_interval: NSTimeInterval,
329 ) -> Retained<Self>;
330
331 #[cfg(feature = "NSURL")]
332 /// Returns the URL of the receiver.
333 ///
334 /// Returns: The URL of the receiver.
335 #[unsafe(method(URL))]
336 #[unsafe(method_family = none)]
337 pub fn URL(&self) -> Option<Retained<NSURL>>;
338
339 /// Returns the cache policy of the receiver.
340 ///
341 /// Returns: The cache policy of the receiver.
342 #[unsafe(method(cachePolicy))]
343 #[unsafe(method_family = none)]
344 pub fn cachePolicy(&self) -> NSURLRequestCachePolicy;
345
346 #[cfg(feature = "NSDate")]
347 /// Returns the timeout interval of the receiver.
348 ///
349 /// The timeout interval specifies the limit on the idle
350 /// interval allotted to a request in the process of loading. The "idle
351 /// interval" is defined as the period of time that has passed since the
352 /// last instance of load activity occurred for a request that is in the
353 /// process of loading. Hence, when an instance of load activity occurs
354 /// (e.g. bytes are received from the network for a request), the idle
355 /// interval for a request is reset to 0. If the idle interval ever
356 /// becomes greater than or equal to the timeout interval, the request
357 /// is considered to have timed out. This timeout interval is measured
358 /// in seconds.
359 ///
360 /// Returns: The timeout interval of the receiver.
361 #[unsafe(method(timeoutInterval))]
362 #[unsafe(method_family = none)]
363 pub fn timeoutInterval(&self) -> NSTimeInterval;
364
365 #[cfg(feature = "NSURL")]
366 /// The main document URL associated with this load.
367 ///
368 /// This URL is used for the cookie "same domain as main
369 /// document" policy, and attributing the request as a sub-resource
370 /// of a user-specified URL. There may also be other future uses.
371 /// See setMainDocumentURL:
372 ///
373 /// Returns: The main document URL.
374 #[unsafe(method(mainDocumentURL))]
375 #[unsafe(method_family = none)]
376 pub fn mainDocumentURL(&self) -> Option<Retained<NSURL>>;
377
378 /// Returns the NSURLRequestNetworkServiceType associated with this request.
379 ///
380 /// This will return NSURLNetworkServiceTypeDefault for requests that have
381 /// not explicitly set a networkServiceType (using the setNetworkServiceType method).
382 ///
383 /// Returns: The NSURLRequestNetworkServiceType associated with this request.
384 #[unsafe(method(networkServiceType))]
385 #[unsafe(method_family = none)]
386 pub fn networkServiceType(&self) -> NSURLRequestNetworkServiceType;
387
388 /// returns whether a connection created with this request is allowed to use
389 /// the built in cellular radios (if present).
390 ///
391 /// Returns: YES if the receiver is allowed to use the built in cellular radios to
392 /// satisfy the request, NO otherwise.
393 #[unsafe(method(allowsCellularAccess))]
394 #[unsafe(method_family = none)]
395 pub fn allowsCellularAccess(&self) -> bool;
396
397 /// returns whether a connection created with this request is allowed to use
398 /// network interfaces which have been marked as expensive.
399 ///
400 /// Returns: YES if the receiver is allowed to use an interface marked as expensive to
401 /// satisfy the request, NO otherwise.
402 #[unsafe(method(allowsExpensiveNetworkAccess))]
403 #[unsafe(method_family = none)]
404 pub fn allowsExpensiveNetworkAccess(&self) -> bool;
405
406 /// returns whether a connection created with this request is allowed to use
407 /// network interfaces which have been marked as constrained.
408 ///
409 /// Returns: YES if the receiver is allowed to use an interface marked as constrained to
410 /// satisfy the request, NO otherwise.
411 #[unsafe(method(allowsConstrainedNetworkAccess))]
412 #[unsafe(method_family = none)]
413 pub fn allowsConstrainedNetworkAccess(&self) -> bool;
414
415 /// returns whether we assume that server supports HTTP/3. Enables QUIC
416 /// racing without HTTP/3 service discovery.
417 ///
418 /// Returns: YES if server endpoint is known to support HTTP/3. Defaults to NO.
419 /// The default may be YES in a future OS update.
420 #[unsafe(method(assumesHTTP3Capable))]
421 #[unsafe(method_family = none)]
422 pub fn assumesHTTP3Capable(&self) -> bool;
423
424 /// Returns the NSURLRequestAttribution associated with this request.
425 ///
426 /// This will return NSURLRequestAttributionDeveloper for requests that
427 /// have not explicitly set an attribution.
428 ///
429 /// Returns: The NSURLRequestAttribution associated with this request.
430 #[unsafe(method(attribution))]
431 #[unsafe(method_family = none)]
432 pub fn attribution(&self) -> NSURLRequestAttribution;
433
434 /// sets whether a request is required to do DNSSEC validation during DNS lookup.
435 ///
436 /// YES, if the DNS lookup for this request should require DNSSEC validation,
437 /// No otherwise. Defaults to NO.
438 #[unsafe(method(requiresDNSSECValidation))]
439 #[unsafe(method_family = none)]
440 pub fn requiresDNSSECValidation(&self) -> bool;
441
442 /// Allows storing and usage of DNS answers, potentially beyond TTL expiry,
443 /// in a persistent per-process cache. This should only be set for hostnames whose resolutions
444 /// are not expected to change across networks.
445 ///
446 /// YES, if the DNS lookup for this request is allowed to use a persistent per-process cache,
447 /// NO otherwise. Defaults to NO.
448 #[unsafe(method(allowsPersistentDNS))]
449 #[unsafe(method_family = none)]
450 pub fn allowsPersistentDNS(&self) -> bool;
451
452 #[cfg(feature = "NSString")]
453 #[unsafe(method(cookiePartitionIdentifier))]
454 #[unsafe(method_family = none)]
455 pub fn cookiePartitionIdentifier(&self) -> Option<Retained<NSString>>;
456 );
457}
458
459/// Methods declared on superclass `NSObject`.
460impl NSURLRequest {
461 extern_methods!(
462 #[unsafe(method(init))]
463 #[unsafe(method_family = init)]
464 pub fn init(this: Allocated<Self>) -> Retained<Self>;
465
466 #[unsafe(method(new))]
467 #[unsafe(method_family = new)]
468 pub fn new() -> Retained<Self>;
469 );
470}
471
472impl DefaultRetained for NSURLRequest {
473 #[inline]
474 fn default_retained() -> Retained<Self> {
475 Self::new()
476 }
477}
478
479extern_class!(
480 /// An NSMutableURLRequest object represents a mutable URL load
481 /// request in a manner independent of protocol and URL scheme.
482 ///
483 ///
484 /// This specialization of NSURLRequest is provided to aid
485 /// developers who may find it more convenient to mutate a single request
486 /// object for a series of URL loads instead of creating an immutable
487 /// NSURLRequest for each load. This programming model is supported by
488 /// the following contract stipulation between NSMutableURLRequest and
489 /// NSURLConnection: NSURLConnection makes a deep copy of each
490 /// NSMutableURLRequest object passed to one of its initializers.
491 /// <p>
492 /// NSMutableURLRequest is designed to be extended to support
493 /// protocol-specific data by adding categories to access a property
494 /// object provided in an interface targeted at protocol implementors.
495 /// <ul>
496 /// <li>
497 /// Protocol implementors should direct their attention to the
498 /// NSMutableURLRequestExtensibility category on
499 /// NSMutableURLRequest for more information on how to provide
500 /// extensions on NSMutableURLRequest to support protocol-specific
501 /// request information.
502 /// <li>
503 /// Clients of this API who wish to create NSMutableURLRequest
504 /// objects to load URL content should consult the protocol-specific
505 /// NSMutableURLRequest categories that are available. The
506 /// NSMutableHTTPURLRequest category on NSMutableURLRequest is an
507 /// example.
508 /// </ul>
509 ///
510 /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmutableurlrequest?language=objc)
511 #[unsafe(super(NSURLRequest, NSObject))]
512 #[derive(Debug, PartialEq, Eq, Hash)]
513 pub struct NSMutableURLRequest;
514);
515
516#[cfg(feature = "NSObject")]
517extern_conformance!(
518 unsafe impl NSCoding for NSMutableURLRequest {}
519);
520
521#[cfg(feature = "NSObject")]
522extern_conformance!(
523 unsafe impl NSCopying for NSMutableURLRequest {}
524);
525
526#[cfg(feature = "NSObject")]
527unsafe impl CopyingHelper for NSMutableURLRequest {
528 type Result = NSURLRequest;
529}
530
531#[cfg(feature = "NSObject")]
532extern_conformance!(
533 unsafe impl NSMutableCopying for NSMutableURLRequest {}
534);
535
536#[cfg(feature = "NSObject")]
537unsafe impl MutableCopyingHelper for NSMutableURLRequest {
538 type Result = Self;
539}
540
541extern_conformance!(
542 unsafe impl NSObjectProtocol for NSMutableURLRequest {}
543);
544
545#[cfg(feature = "NSObject")]
546extern_conformance!(
547 unsafe impl NSSecureCoding for NSMutableURLRequest {}
548);
549
550impl NSMutableURLRequest {
551 extern_methods!(
552 #[cfg(feature = "NSURL")]
553 /// The URL of the receiver.
554 #[unsafe(method(URL))]
555 #[unsafe(method_family = none)]
556 pub fn URL(&self) -> Option<Retained<NSURL>>;
557
558 #[cfg(feature = "NSURL")]
559 /// Setter for [`URL`][Self::URL].
560 ///
561 /// This is [copied][crate::NSCopying::copy] when set.
562 #[unsafe(method(setURL:))]
563 #[unsafe(method_family = none)]
564 pub fn setURL(&self, url: Option<&NSURL>);
565
566 /// The cache policy of the receiver.
567 #[unsafe(method(cachePolicy))]
568 #[unsafe(method_family = none)]
569 pub fn cachePolicy(&self) -> NSURLRequestCachePolicy;
570
571 /// Setter for [`cachePolicy`][Self::cachePolicy].
572 #[unsafe(method(setCachePolicy:))]
573 #[unsafe(method_family = none)]
574 pub fn setCachePolicy(&self, cache_policy: NSURLRequestCachePolicy);
575
576 #[cfg(feature = "NSDate")]
577 /// Sets the timeout interval of the receiver.
578 ///
579 /// The timeout interval specifies the limit on the idle
580 /// interval allotted to a request in the process of loading. The "idle
581 /// interval" is defined as the period of time that has passed since the
582 /// last instance of load activity occurred for a request that is in the
583 /// process of loading. Hence, when an instance of load activity occurs
584 /// (e.g. bytes are received from the network for a request), the idle
585 /// interval for a request is reset to 0. If the idle interval ever
586 /// becomes greater than or equal to the timeout interval, the request
587 /// is considered to have timed out. This timeout interval is measured
588 /// in seconds.
589 #[unsafe(method(timeoutInterval))]
590 #[unsafe(method_family = none)]
591 pub fn timeoutInterval(&self) -> NSTimeInterval;
592
593 #[cfg(feature = "NSDate")]
594 /// Setter for [`timeoutInterval`][Self::timeoutInterval].
595 #[unsafe(method(setTimeoutInterval:))]
596 #[unsafe(method_family = none)]
597 pub fn setTimeoutInterval(&self, timeout_interval: NSTimeInterval);
598
599 #[cfg(feature = "NSURL")]
600 /// Sets the main document URL
601 ///
602 /// The caller should pass the URL for an appropriate main
603 /// document, if known. For example, when loading a web page, the URL
604 /// of the main html document for the top-level frame should be
605 /// passed. This main document is used to implement the cookie "only
606 /// from same domain as main document" policy, attributing this request
607 /// as a sub-resource of a user-specified URL, and possibly other things
608 /// in the future.
609 #[unsafe(method(mainDocumentURL))]
610 #[unsafe(method_family = none)]
611 pub fn mainDocumentURL(&self) -> Option<Retained<NSURL>>;
612
613 #[cfg(feature = "NSURL")]
614 /// Setter for [`mainDocumentURL`][Self::mainDocumentURL].
615 ///
616 /// This is [copied][crate::NSCopying::copy] when set.
617 #[unsafe(method(setMainDocumentURL:))]
618 #[unsafe(method_family = none)]
619 pub fn setMainDocumentURL(&self, main_document_url: Option<&NSURL>);
620
621 /// Sets the NSURLRequestNetworkServiceType to associate with this request
622 ///
623 /// This method is used to provide the network layers with a hint as to the purpose
624 /// of the request. Most clients should not need to use this method.
625 #[unsafe(method(networkServiceType))]
626 #[unsafe(method_family = none)]
627 pub fn networkServiceType(&self) -> NSURLRequestNetworkServiceType;
628
629 /// Setter for [`networkServiceType`][Self::networkServiceType].
630 #[unsafe(method(setNetworkServiceType:))]
631 #[unsafe(method_family = none)]
632 pub fn setNetworkServiceType(&self, network_service_type: NSURLRequestNetworkServiceType);
633
634 /// sets whether a connection created with this request is allowed to use
635 /// the built in cellular radios (if present).
636 ///
637 /// NO if the receiver should not be allowed to use the built in
638 /// cellular radios to satisfy the request, YES otherwise. The default is YES.
639 #[unsafe(method(allowsCellularAccess))]
640 #[unsafe(method_family = none)]
641 pub fn allowsCellularAccess(&self) -> bool;
642
643 /// Setter for [`allowsCellularAccess`][Self::allowsCellularAccess].
644 #[unsafe(method(setAllowsCellularAccess:))]
645 #[unsafe(method_family = none)]
646 pub fn setAllowsCellularAccess(&self, allows_cellular_access: bool);
647
648 /// sets whether a connection created with this request is allowed to use
649 /// network interfaces which have been marked as expensive.
650 ///
651 /// NO if the receiver should not be allowed to use an interface marked as expensive to
652 /// satisfy the request, YES otherwise.
653 #[unsafe(method(allowsExpensiveNetworkAccess))]
654 #[unsafe(method_family = none)]
655 pub fn allowsExpensiveNetworkAccess(&self) -> bool;
656
657 /// Setter for [`allowsExpensiveNetworkAccess`][Self::allowsExpensiveNetworkAccess].
658 #[unsafe(method(setAllowsExpensiveNetworkAccess:))]
659 #[unsafe(method_family = none)]
660 pub fn setAllowsExpensiveNetworkAccess(&self, allows_expensive_network_access: bool);
661
662 /// sets whether a connection created with this request is allowed to use
663 /// network interfaces which have been marked as constrained.
664 ///
665 /// NO if the receiver should not be allowed to use an interface marked as constrained to
666 /// satisfy the request, YES otherwise.
667 #[unsafe(method(allowsConstrainedNetworkAccess))]
668 #[unsafe(method_family = none)]
669 pub fn allowsConstrainedNetworkAccess(&self) -> bool;
670
671 /// Setter for [`allowsConstrainedNetworkAccess`][Self::allowsConstrainedNetworkAccess].
672 #[unsafe(method(setAllowsConstrainedNetworkAccess:))]
673 #[unsafe(method_family = none)]
674 pub fn setAllowsConstrainedNetworkAccess(&self, allows_constrained_network_access: bool);
675
676 /// returns whether we assume that server supports HTTP/3. Enables QUIC
677 /// racing without HTTP/3 service discovery.
678 ///
679 /// Returns: YES if server endpoint is known to support HTTP/3. Defaults to NO.
680 /// The default may be YES in a future OS update.
681 #[unsafe(method(assumesHTTP3Capable))]
682 #[unsafe(method_family = none)]
683 pub fn assumesHTTP3Capable(&self) -> bool;
684
685 /// Setter for [`assumesHTTP3Capable`][Self::assumesHTTP3Capable].
686 #[unsafe(method(setAssumesHTTP3Capable:))]
687 #[unsafe(method_family = none)]
688 pub fn setAssumesHTTP3Capable(&self, assumes_http3_capable: bool);
689
690 /// Sets the NSURLRequestAttribution to associate with this request.
691 ///
692 /// Set to NSURLRequestAttributionUser if the URL was specified by the
693 /// user. Defaults to NSURLRequestAttributionDeveloper.
694 #[unsafe(method(attribution))]
695 #[unsafe(method_family = none)]
696 pub fn attribution(&self) -> NSURLRequestAttribution;
697
698 /// Setter for [`attribution`][Self::attribution].
699 #[unsafe(method(setAttribution:))]
700 #[unsafe(method_family = none)]
701 pub fn setAttribution(&self, attribution: NSURLRequestAttribution);
702
703 /// sets whether a request is required to do DNSSEC validation during DNS lookup.
704 ///
705 /// YES, if the DNS lookup for this request should require DNSSEC validation,
706 /// No otherwise. Defaults to NO.
707 #[unsafe(method(requiresDNSSECValidation))]
708 #[unsafe(method_family = none)]
709 pub fn requiresDNSSECValidation(&self) -> bool;
710
711 /// Setter for [`requiresDNSSECValidation`][Self::requiresDNSSECValidation].
712 #[unsafe(method(setRequiresDNSSECValidation:))]
713 #[unsafe(method_family = none)]
714 pub fn setRequiresDNSSECValidation(&self, requires_dnssec_validation: bool);
715
716 /// Allows storing and usage of DNS answers, potentially beyond TTL expiry,
717 /// in a persistent per-process cache. This should only be set for hostnames whose resolutions
718 /// are not expected to change across networks.
719 ///
720 /// YES, if the DNS lookup for this request is allowed to use a persistent per-process cache,
721 /// NO otherwise. Defaults to NO.
722 #[unsafe(method(allowsPersistentDNS))]
723 #[unsafe(method_family = none)]
724 pub fn allowsPersistentDNS(&self) -> bool;
725
726 /// Setter for [`allowsPersistentDNS`][Self::allowsPersistentDNS].
727 #[unsafe(method(setAllowsPersistentDNS:))]
728 #[unsafe(method_family = none)]
729 pub fn setAllowsPersistentDNS(&self, allows_persistent_dns: bool);
730
731 #[cfg(feature = "NSString")]
732 #[unsafe(method(cookiePartitionIdentifier))]
733 #[unsafe(method_family = none)]
734 pub fn cookiePartitionIdentifier(&self) -> Option<Retained<NSString>>;
735
736 #[cfg(feature = "NSString")]
737 /// Setter for [`cookiePartitionIdentifier`][Self::cookiePartitionIdentifier].
738 ///
739 /// This is [copied][crate::NSCopying::copy] when set.
740 #[unsafe(method(setCookiePartitionIdentifier:))]
741 #[unsafe(method_family = none)]
742 pub fn setCookiePartitionIdentifier(&self, cookie_partition_identifier: Option<&NSString>);
743 );
744}
745
746/// Methods declared on superclass `NSURLRequest`.
747impl NSMutableURLRequest {
748 extern_methods!(
749 #[cfg(feature = "NSURL")]
750 /// Allocates and initializes an NSURLRequest with the given
751 /// URL.
752 ///
753 /// Default values are used for cache policy
754 /// (NSURLRequestUseProtocolCachePolicy) and timeout interval (60
755 /// seconds).
756 ///
757 /// Parameter `URL`: The URL for the request.
758 ///
759 /// Returns: A newly-created and autoreleased NSURLRequest instance.
760 #[unsafe(method(requestWithURL:))]
761 #[unsafe(method_family = none)]
762 pub fn requestWithURL(url: &NSURL) -> Retained<Self>;
763
764 #[cfg(all(feature = "NSDate", feature = "NSURL"))]
765 /// Allocates and initializes a NSURLRequest with the given
766 /// URL and cache policy.
767 ///
768 /// Parameter `URL`: The URL for the request.
769 ///
770 /// Parameter `cachePolicy`: The cache policy for the request.
771 ///
772 /// Parameter `timeoutInterval`: The timeout interval for the request. See the
773 /// commentary for the
774 /// <tt>
775 /// timeoutInterval
776 /// </tt>
777 /// for more information on
778 /// timeout intervals.
779 ///
780 /// Returns: A newly-created and autoreleased NSURLRequest instance.
781 #[unsafe(method(requestWithURL:cachePolicy:timeoutInterval:))]
782 #[unsafe(method_family = none)]
783 pub fn requestWithURL_cachePolicy_timeoutInterval(
784 url: &NSURL,
785 cache_policy: NSURLRequestCachePolicy,
786 timeout_interval: NSTimeInterval,
787 ) -> Retained<Self>;
788
789 #[cfg(feature = "NSURL")]
790 /// Initializes an NSURLRequest with the given URL.
791 ///
792 /// Default values are used for cache policy
793 /// (NSURLRequestUseProtocolCachePolicy) and timeout interval (60
794 /// seconds).
795 ///
796 /// Parameter `URL`: The URL for the request.
797 ///
798 /// Returns: An initialized NSURLRequest.
799 #[unsafe(method(initWithURL:))]
800 #[unsafe(method_family = init)]
801 pub fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>;
802
803 #[cfg(all(feature = "NSDate", feature = "NSURL"))]
804 /// Initializes an NSURLRequest with the given URL and
805 /// cache policy.
806 ///
807 /// This is the designated initializer for the
808 /// NSURLRequest class.
809 ///
810 /// Parameter `URL`: The URL for the request.
811 ///
812 /// Parameter `cachePolicy`: The cache policy for the request.
813 ///
814 /// Parameter `timeoutInterval`: The timeout interval for the request. See the
815 /// commentary for the
816 /// <tt>
817 /// timeoutInterval
818 /// </tt>
819 /// for more information on
820 /// timeout intervals.
821 ///
822 /// Returns: An initialized NSURLRequest.
823 #[unsafe(method(initWithURL:cachePolicy:timeoutInterval:))]
824 #[unsafe(method_family = init)]
825 pub fn initWithURL_cachePolicy_timeoutInterval(
826 this: Allocated<Self>,
827 url: &NSURL,
828 cache_policy: NSURLRequestCachePolicy,
829 timeout_interval: NSTimeInterval,
830 ) -> Retained<Self>;
831 );
832}
833
834/// Methods declared on superclass `NSObject`.
835impl NSMutableURLRequest {
836 extern_methods!(
837 #[unsafe(method(init))]
838 #[unsafe(method_family = init)]
839 pub fn init(this: Allocated<Self>) -> Retained<Self>;
840
841 #[unsafe(method(new))]
842 #[unsafe(method_family = new)]
843 pub fn new() -> Retained<Self>;
844 );
845}
846
847impl DefaultRetained for NSMutableURLRequest {
848 #[inline]
849 fn default_retained() -> Retained<Self> {
850 Self::new()
851 }
852}
853
854/// NSHTTPURLRequest.
855///
856/// The NSHTTPURLRequest on NSURLRequest provides methods for accessing
857/// information specific to HTTP protocol requests.
858impl NSURLRequest {
859 extern_methods!(
860 #[cfg(feature = "NSString")]
861 /// Returns the HTTP request method of the receiver.
862 ///
863 /// Returns: the HTTP request method of the receiver.
864 #[unsafe(method(HTTPMethod))]
865 #[unsafe(method_family = none)]
866 pub fn HTTPMethod(&self) -> Option<Retained<NSString>>;
867
868 #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
869 /// Returns a dictionary containing all the HTTP header fields
870 /// of the receiver.
871 ///
872 /// Returns: a dictionary containing all the HTTP header fields of the
873 /// receiver.
874 #[unsafe(method(allHTTPHeaderFields))]
875 #[unsafe(method_family = none)]
876 pub fn allHTTPHeaderFields(&self) -> Option<Retained<NSDictionary<NSString, NSString>>>;
877
878 #[cfg(feature = "NSString")]
879 /// Returns the value which corresponds to the given header
880 /// field. Note that, in keeping with the HTTP RFC, HTTP header field
881 /// names are case-insensitive.
882 ///
883 /// Parameter `field`: the header field name to use for the lookup
884 /// (case-insensitive).
885 ///
886 /// Returns: the value associated with the given header field, or nil if
887 /// there is no value associated with the given header field.
888 #[unsafe(method(valueForHTTPHeaderField:))]
889 #[unsafe(method_family = none)]
890 pub fn valueForHTTPHeaderField(&self, field: &NSString) -> Option<Retained<NSString>>;
891
892 #[cfg(feature = "NSData")]
893 /// Returns the request body data of the receiver.
894 ///
895 /// This data is sent as the message body of the request, as
896 /// in done in an HTTP POST request.
897 ///
898 /// Returns: The request body data of the receiver.
899 #[unsafe(method(HTTPBody))]
900 #[unsafe(method_family = none)]
901 pub fn HTTPBody(&self) -> Option<Retained<NSData>>;
902
903 #[cfg(feature = "NSStream")]
904 /// Returns the request body stream of the receiver
905 /// if any has been set
906 ///
907 /// The stream is returned for examination only; it is
908 /// not safe for the caller to manipulate the stream in any way. Also
909 /// note that the HTTPBodyStream and HTTPBody are mutually exclusive - only
910 /// one can be set on a given request. Also note that the body stream is
911 /// preserved across copies, but is LOST when the request is coded via the
912 /// NSCoding protocol
913 ///
914 /// Returns: The request body stream of the receiver.
915 #[unsafe(method(HTTPBodyStream))]
916 #[unsafe(method_family = none)]
917 pub fn HTTPBodyStream(&self) -> Option<Retained<NSInputStream>>;
918
919 /// Determine whether default cookie handling will happen for
920 /// this request.
921 ///
922 /// NOTE: This value is not used prior to 10.3
923 ///
924 /// Returns: YES if cookies will be sent with and set for this request;
925 /// otherwise NO.
926 #[unsafe(method(HTTPShouldHandleCookies))]
927 #[unsafe(method_family = none)]
928 pub fn HTTPShouldHandleCookies(&self) -> bool;
929
930 /// Reports whether the receiver is not expected to wait for the
931 /// previous response before transmitting.
932 ///
933 /// Returns: YES if the receiver should transmit before the previous response
934 /// is received. NO if the receiver should wait for the previous response
935 /// before transmitting.
936 #[deprecated = "Only supported in the classic loader, please adopt HTTP/2 and HTTP/3 instead"]
937 #[unsafe(method(HTTPShouldUsePipelining))]
938 #[unsafe(method_family = none)]
939 pub fn HTTPShouldUsePipelining(&self) -> bool;
940 );
941}
942
943/// NSMutableHTTPURLRequest.
944///
945/// The NSMutableHTTPURLRequest on NSMutableURLRequest provides methods
946/// for configuring information specific to HTTP protocol requests.
947impl NSMutableURLRequest {
948 extern_methods!(
949 #[cfg(feature = "NSString")]
950 /// Sets the HTTP request method of the receiver.
951 #[unsafe(method(HTTPMethod))]
952 #[unsafe(method_family = none)]
953 pub fn HTTPMethod(&self) -> Retained<NSString>;
954
955 #[cfg(feature = "NSString")]
956 /// Setter for [`HTTPMethod`][Self::HTTPMethod].
957 ///
958 /// This is [copied][crate::NSCopying::copy] when set.
959 #[unsafe(method(setHTTPMethod:))]
960 #[unsafe(method_family = none)]
961 pub fn setHTTPMethod(&self, http_method: &NSString);
962
963 #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
964 /// Sets the HTTP header fields of the receiver to the given
965 /// dictionary.
966 ///
967 /// This method replaces all header fields that may have
968 /// existed before this method call.
969 /// <p>
970 /// Since HTTP header fields must be string values, each object and
971 /// key in the dictionary passed to this method must answer YES when
972 /// sent an
973 /// <tt>
974 /// -isKindOfClass:[NSString class]
975 /// </tt>
976 /// message. If either
977 /// the key or value for a key-value pair answers NO when sent this
978 /// message, the key-value pair is skipped.
979 #[unsafe(method(allHTTPHeaderFields))]
980 #[unsafe(method_family = none)]
981 pub fn allHTTPHeaderFields(&self) -> Option<Retained<NSDictionary<NSString, NSString>>>;
982
983 #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
984 /// Setter for [`allHTTPHeaderFields`][Self::allHTTPHeaderFields].
985 ///
986 /// This is [copied][crate::NSCopying::copy] when set.
987 #[unsafe(method(setAllHTTPHeaderFields:))]
988 #[unsafe(method_family = none)]
989 pub fn setAllHTTPHeaderFields(
990 &self,
991 all_http_header_fields: Option<&NSDictionary<NSString, NSString>>,
992 );
993
994 #[cfg(feature = "NSString")]
995 /// Sets the value of the given HTTP header field.
996 ///
997 /// If a value was previously set for the given header
998 /// field, that value is replaced with the given value. Note that, in
999 /// keeping with the HTTP RFC, HTTP header field names are
1000 /// case-insensitive.
1001 ///
1002 /// Parameter `value`: the header field value.
1003 ///
1004 /// Parameter `field`: the header field name (case-insensitive).
1005 #[unsafe(method(setValue:forHTTPHeaderField:))]
1006 #[unsafe(method_family = none)]
1007 pub fn setValue_forHTTPHeaderField(&self, value: Option<&NSString>, field: &NSString);
1008
1009 #[cfg(feature = "NSString")]
1010 /// Adds an HTTP header field in the current header
1011 /// dictionary.
1012 ///
1013 /// This method provides a way to add values to header
1014 /// fields incrementally. If a value was previously set for the given
1015 /// header field, the given value is appended to the previously-existing
1016 /// value. The appropriate field delimiter, a comma in the case of HTTP,
1017 /// is added by the implementation, and should not be added to the given
1018 /// value by the caller. Note that, in keeping with the HTTP RFC, HTTP
1019 /// header field names are case-insensitive.
1020 ///
1021 /// Parameter `value`: the header field value.
1022 ///
1023 /// Parameter `field`: the header field name (case-insensitive).
1024 #[unsafe(method(addValue:forHTTPHeaderField:))]
1025 #[unsafe(method_family = none)]
1026 pub fn addValue_forHTTPHeaderField(&self, value: &NSString, field: &NSString);
1027
1028 #[cfg(feature = "NSData")]
1029 /// Sets the request body data of the receiver.
1030 ///
1031 /// This data is sent as the message body of the request, as
1032 /// in done in an HTTP POST request.
1033 #[unsafe(method(HTTPBody))]
1034 #[unsafe(method_family = none)]
1035 pub fn HTTPBody(&self) -> Option<Retained<NSData>>;
1036
1037 #[cfg(feature = "NSData")]
1038 /// Setter for [`HTTPBody`][Self::HTTPBody].
1039 ///
1040 /// This is [copied][crate::NSCopying::copy] when set.
1041 #[unsafe(method(setHTTPBody:))]
1042 #[unsafe(method_family = none)]
1043 pub fn setHTTPBody(&self, http_body: Option<&NSData>);
1044
1045 #[cfg(feature = "NSStream")]
1046 /// Sets the request body to be the contents of the given stream.
1047 ///
1048 /// The provided stream should be unopened; the request will take
1049 /// over the stream's delegate. The entire stream's contents will be
1050 /// transmitted as the HTTP body of the request. Note that the body stream
1051 /// and the body data (set by setHTTPBody:, above) are mutually exclusive
1052 /// - setting one will clear the other.
1053 #[unsafe(method(HTTPBodyStream))]
1054 #[unsafe(method_family = none)]
1055 pub fn HTTPBodyStream(&self) -> Option<Retained<NSInputStream>>;
1056
1057 #[cfg(feature = "NSStream")]
1058 /// Setter for [`HTTPBodyStream`][Self::HTTPBodyStream].
1059 #[unsafe(method(setHTTPBodyStream:))]
1060 #[unsafe(method_family = none)]
1061 pub fn setHTTPBodyStream(&self, http_body_stream: Option<&NSInputStream>);
1062
1063 /// Decide whether default cookie handling will happen for
1064 /// this request (YES if cookies should be sent with and set for this request;
1065 /// otherwise NO).
1066 ///
1067 /// The default is YES - in other words, cookies are sent from and
1068 /// stored to the cookie manager by default.
1069 /// NOTE: In releases prior to 10.3, this value is ignored
1070 #[unsafe(method(HTTPShouldHandleCookies))]
1071 #[unsafe(method_family = none)]
1072 pub fn HTTPShouldHandleCookies(&self) -> bool;
1073
1074 /// Setter for [`HTTPShouldHandleCookies`][Self::HTTPShouldHandleCookies].
1075 #[unsafe(method(setHTTPShouldHandleCookies:))]
1076 #[unsafe(method_family = none)]
1077 pub fn setHTTPShouldHandleCookies(&self, http_should_handle_cookies: bool);
1078
1079 /// Sets whether the request should not wait for the previous response
1080 /// before transmitting (YES if the receiver should transmit before the previous response is
1081 /// received. NO to wait for the previous response before transmitting)
1082 ///
1083 /// Calling this method with a YES value does not guarantee HTTP
1084 /// pipelining behavior. This method may have no effect if an HTTP proxy is
1085 /// configured, or if the HTTP request uses an unsafe request method (e.g., POST
1086 /// requests will not pipeline). Pipelining behavior also may not begin until
1087 /// the second request on a given TCP connection. There may be other situations
1088 /// where pipelining does not occur even though YES was set.
1089 /// HTTP 1.1 allows the client to send multiple requests to the server without
1090 /// waiting for a response. Though HTTP 1.1 requires support for pipelining,
1091 /// some servers report themselves as being HTTP 1.1 but do not support
1092 /// pipelining (disconnecting, sending resources misordered, omitting part of
1093 /// a resource, etc.).
1094 #[deprecated = "Only supported in the classic loader, please adopt HTTP/2 and HTTP/3 instead"]
1095 #[unsafe(method(HTTPShouldUsePipelining))]
1096 #[unsafe(method_family = none)]
1097 pub fn HTTPShouldUsePipelining(&self) -> bool;
1098
1099 /// Setter for [`HTTPShouldUsePipelining`][Self::HTTPShouldUsePipelining].
1100 #[deprecated = "Only supported in the classic loader, please adopt HTTP/2 and HTTP/3 instead"]
1101 #[unsafe(method(setHTTPShouldUsePipelining:))]
1102 #[unsafe(method_family = none)]
1103 pub fn setHTTPShouldUsePipelining(&self, http_should_use_pipelining: bool);
1104 );
1105}