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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe fn allowsPersistentDNS(&self) -> bool;
451
452 #[cfg(feature = "NSString")]
453 #[unsafe(method(cookiePartitionIdentifier))]
454 #[unsafe(method_family = none)]
455 pub unsafe 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 unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
465
466 #[unsafe(method(new))]
467 #[unsafe(method_family = new)]
468 pub unsafe fn new() -> Retained<Self>;
469 );
470}
471
472extern_class!(
473 /// An NSMutableURLRequest object represents a mutable URL load
474 /// request in a manner independent of protocol and URL scheme.
475 ///
476 ///
477 /// This specialization of NSURLRequest is provided to aid
478 /// developers who may find it more convenient to mutate a single request
479 /// object for a series of URL loads instead of creating an immutable
480 /// NSURLRequest for each load. This programming model is supported by
481 /// the following contract stipulation between NSMutableURLRequest and
482 /// NSURLConnection: NSURLConnection makes a deep copy of each
483 /// NSMutableURLRequest object passed to one of its initializers.
484 /// <p>
485 /// NSMutableURLRequest is designed to be extended to support
486 /// protocol-specific data by adding categories to access a property
487 /// object provided in an interface targeted at protocol implementors.
488 /// <ul>
489 /// <li>
490 /// Protocol implementors should direct their attention to the
491 /// NSMutableURLRequestExtensibility category on
492 /// NSMutableURLRequest for more information on how to provide
493 /// extensions on NSMutableURLRequest to support protocol-specific
494 /// request information.
495 /// <li>
496 /// Clients of this API who wish to create NSMutableURLRequest
497 /// objects to load URL content should consult the protocol-specific
498 /// NSMutableURLRequest categories that are available. The
499 /// NSMutableHTTPURLRequest category on NSMutableURLRequest is an
500 /// example.
501 /// </ul>
502 ///
503 /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmutableurlrequest?language=objc)
504 #[unsafe(super(NSURLRequest, NSObject))]
505 #[derive(Debug, PartialEq, Eq, Hash)]
506 pub struct NSMutableURLRequest;
507);
508
509#[cfg(feature = "NSObject")]
510extern_conformance!(
511 unsafe impl NSCoding for NSMutableURLRequest {}
512);
513
514#[cfg(feature = "NSObject")]
515extern_conformance!(
516 unsafe impl NSCopying for NSMutableURLRequest {}
517);
518
519#[cfg(feature = "NSObject")]
520unsafe impl CopyingHelper for NSMutableURLRequest {
521 type Result = NSURLRequest;
522}
523
524#[cfg(feature = "NSObject")]
525extern_conformance!(
526 unsafe impl NSMutableCopying for NSMutableURLRequest {}
527);
528
529#[cfg(feature = "NSObject")]
530unsafe impl MutableCopyingHelper for NSMutableURLRequest {
531 type Result = Self;
532}
533
534extern_conformance!(
535 unsafe impl NSObjectProtocol for NSMutableURLRequest {}
536);
537
538#[cfg(feature = "NSObject")]
539extern_conformance!(
540 unsafe impl NSSecureCoding for NSMutableURLRequest {}
541);
542
543impl NSMutableURLRequest {
544 extern_methods!(
545 #[cfg(feature = "NSURL")]
546 /// The URL of the receiver.
547 #[unsafe(method(URL))]
548 #[unsafe(method_family = none)]
549 pub unsafe fn URL(&self) -> Option<Retained<NSURL>>;
550
551 #[cfg(feature = "NSURL")]
552 /// Setter for [`URL`][Self::URL].
553 #[unsafe(method(setURL:))]
554 #[unsafe(method_family = none)]
555 pub unsafe fn setURL(&self, url: Option<&NSURL>);
556
557 /// The cache policy of the receiver.
558 #[unsafe(method(cachePolicy))]
559 #[unsafe(method_family = none)]
560 pub unsafe fn cachePolicy(&self) -> NSURLRequestCachePolicy;
561
562 /// Setter for [`cachePolicy`][Self::cachePolicy].
563 #[unsafe(method(setCachePolicy:))]
564 #[unsafe(method_family = none)]
565 pub unsafe fn setCachePolicy(&self, cache_policy: NSURLRequestCachePolicy);
566
567 #[cfg(feature = "NSDate")]
568 /// Sets the timeout interval of the receiver.
569 ///
570 /// The timeout interval specifies the limit on the idle
571 /// interval allotted to a request in the process of loading. The "idle
572 /// interval" is defined as the period of time that has passed since the
573 /// last instance of load activity occurred for a request that is in the
574 /// process of loading. Hence, when an instance of load activity occurs
575 /// (e.g. bytes are received from the network for a request), the idle
576 /// interval for a request is reset to 0. If the idle interval ever
577 /// becomes greater than or equal to the timeout interval, the request
578 /// is considered to have timed out. This timeout interval is measured
579 /// in seconds.
580 #[unsafe(method(timeoutInterval))]
581 #[unsafe(method_family = none)]
582 pub unsafe fn timeoutInterval(&self) -> NSTimeInterval;
583
584 #[cfg(feature = "NSDate")]
585 /// Setter for [`timeoutInterval`][Self::timeoutInterval].
586 #[unsafe(method(setTimeoutInterval:))]
587 #[unsafe(method_family = none)]
588 pub unsafe fn setTimeoutInterval(&self, timeout_interval: NSTimeInterval);
589
590 #[cfg(feature = "NSURL")]
591 /// Sets the main document URL
592 ///
593 /// The caller should pass the URL for an appropriate main
594 /// document, if known. For example, when loading a web page, the URL
595 /// of the main html document for the top-level frame should be
596 /// passed. This main document is used to implement the cookie "only
597 /// from same domain as main document" policy, attributing this request
598 /// as a sub-resource of a user-specified URL, and possibly other things
599 /// in the future.
600 #[unsafe(method(mainDocumentURL))]
601 #[unsafe(method_family = none)]
602 pub unsafe fn mainDocumentURL(&self) -> Option<Retained<NSURL>>;
603
604 #[cfg(feature = "NSURL")]
605 /// Setter for [`mainDocumentURL`][Self::mainDocumentURL].
606 #[unsafe(method(setMainDocumentURL:))]
607 #[unsafe(method_family = none)]
608 pub unsafe fn setMainDocumentURL(&self, main_document_url: Option<&NSURL>);
609
610 /// Sets the NSURLRequestNetworkServiceType to associate with this request
611 ///
612 /// This method is used to provide the network layers with a hint as to the purpose
613 /// of the request. Most clients should not need to use this method.
614 #[unsafe(method(networkServiceType))]
615 #[unsafe(method_family = none)]
616 pub unsafe fn networkServiceType(&self) -> NSURLRequestNetworkServiceType;
617
618 /// Setter for [`networkServiceType`][Self::networkServiceType].
619 #[unsafe(method(setNetworkServiceType:))]
620 #[unsafe(method_family = none)]
621 pub unsafe fn setNetworkServiceType(
622 &self,
623 network_service_type: NSURLRequestNetworkServiceType,
624 );
625
626 /// sets whether a connection created with this request is allowed to use
627 /// the built in cellular radios (if present).
628 ///
629 /// NO if the receiver should not be allowed to use the built in
630 /// cellular radios to satisfy the request, YES otherwise. The default is YES.
631 #[unsafe(method(allowsCellularAccess))]
632 #[unsafe(method_family = none)]
633 pub unsafe fn allowsCellularAccess(&self) -> bool;
634
635 /// Setter for [`allowsCellularAccess`][Self::allowsCellularAccess].
636 #[unsafe(method(setAllowsCellularAccess:))]
637 #[unsafe(method_family = none)]
638 pub unsafe fn setAllowsCellularAccess(&self, allows_cellular_access: bool);
639
640 /// sets whether a connection created with this request is allowed to use
641 /// network interfaces which have been marked as expensive.
642 ///
643 /// NO if the receiver should not be allowed to use an interface marked as expensive to
644 /// satisfy the request, YES otherwise.
645 #[unsafe(method(allowsExpensiveNetworkAccess))]
646 #[unsafe(method_family = none)]
647 pub unsafe fn allowsExpensiveNetworkAccess(&self) -> bool;
648
649 /// Setter for [`allowsExpensiveNetworkAccess`][Self::allowsExpensiveNetworkAccess].
650 #[unsafe(method(setAllowsExpensiveNetworkAccess:))]
651 #[unsafe(method_family = none)]
652 pub unsafe fn setAllowsExpensiveNetworkAccess(&self, allows_expensive_network_access: bool);
653
654 /// sets whether a connection created with this request is allowed to use
655 /// network interfaces which have been marked as constrained.
656 ///
657 /// NO if the receiver should not be allowed to use an interface marked as constrained to
658 /// satisfy the request, YES otherwise.
659 #[unsafe(method(allowsConstrainedNetworkAccess))]
660 #[unsafe(method_family = none)]
661 pub unsafe fn allowsConstrainedNetworkAccess(&self) -> bool;
662
663 /// Setter for [`allowsConstrainedNetworkAccess`][Self::allowsConstrainedNetworkAccess].
664 #[unsafe(method(setAllowsConstrainedNetworkAccess:))]
665 #[unsafe(method_family = none)]
666 pub unsafe fn setAllowsConstrainedNetworkAccess(
667 &self,
668 allows_constrained_network_access: bool,
669 );
670
671 /// returns whether we assume that server supports HTTP/3. Enables QUIC
672 /// racing without HTTP/3 service discovery.
673 ///
674 /// Returns: YES if server endpoint is known to support HTTP/3. Defaults to NO.
675 /// The default may be YES in a future OS update.
676 #[unsafe(method(assumesHTTP3Capable))]
677 #[unsafe(method_family = none)]
678 pub unsafe fn assumesHTTP3Capable(&self) -> bool;
679
680 /// Setter for [`assumesHTTP3Capable`][Self::assumesHTTP3Capable].
681 #[unsafe(method(setAssumesHTTP3Capable:))]
682 #[unsafe(method_family = none)]
683 pub unsafe fn setAssumesHTTP3Capable(&self, assumes_http3_capable: bool);
684
685 /// Sets the NSURLRequestAttribution to associate with this request.
686 ///
687 /// Set to NSURLRequestAttributionUser if the URL was specified by the
688 /// user. Defaults to NSURLRequestAttributionDeveloper.
689 #[unsafe(method(attribution))]
690 #[unsafe(method_family = none)]
691 pub unsafe fn attribution(&self) -> NSURLRequestAttribution;
692
693 /// Setter for [`attribution`][Self::attribution].
694 #[unsafe(method(setAttribution:))]
695 #[unsafe(method_family = none)]
696 pub unsafe fn setAttribution(&self, attribution: NSURLRequestAttribution);
697
698 /// sets whether a request is required to do DNSSEC validation during DNS lookup.
699 ///
700 /// YES, if the DNS lookup for this request should require DNSSEC validation,
701 /// No otherwise. Defaults to NO.
702 #[unsafe(method(requiresDNSSECValidation))]
703 #[unsafe(method_family = none)]
704 pub unsafe fn requiresDNSSECValidation(&self) -> bool;
705
706 /// Setter for [`requiresDNSSECValidation`][Self::requiresDNSSECValidation].
707 #[unsafe(method(setRequiresDNSSECValidation:))]
708 #[unsafe(method_family = none)]
709 pub unsafe fn setRequiresDNSSECValidation(&self, requires_dnssec_validation: bool);
710
711 /// Allows storing and usage of DNS answers, potentially beyond TTL expiry,
712 /// in a persistent per-process cache. This should only be set for hostnames whose resolutions
713 /// are not expected to change across networks.
714 ///
715 /// YES, if the DNS lookup for this request is allowed to use a persistent per-process cache,
716 /// NO otherwise. Defaults to NO.
717 #[unsafe(method(allowsPersistentDNS))]
718 #[unsafe(method_family = none)]
719 pub unsafe fn allowsPersistentDNS(&self) -> bool;
720
721 /// Setter for [`allowsPersistentDNS`][Self::allowsPersistentDNS].
722 #[unsafe(method(setAllowsPersistentDNS:))]
723 #[unsafe(method_family = none)]
724 pub unsafe fn setAllowsPersistentDNS(&self, allows_persistent_dns: bool);
725
726 #[cfg(feature = "NSString")]
727 #[unsafe(method(cookiePartitionIdentifier))]
728 #[unsafe(method_family = none)]
729 pub unsafe fn cookiePartitionIdentifier(&self) -> Option<Retained<NSString>>;
730
731 #[cfg(feature = "NSString")]
732 /// Setter for [`cookiePartitionIdentifier`][Self::cookiePartitionIdentifier].
733 #[unsafe(method(setCookiePartitionIdentifier:))]
734 #[unsafe(method_family = none)]
735 pub unsafe fn setCookiePartitionIdentifier(
736 &self,
737 cookie_partition_identifier: Option<&NSString>,
738 );
739 );
740}
741
742/// Methods declared on superclass `NSURLRequest`.
743impl NSMutableURLRequest {
744 extern_methods!(
745 #[cfg(feature = "NSURL")]
746 /// Allocates and initializes an NSURLRequest with the given
747 /// URL.
748 ///
749 /// Default values are used for cache policy
750 /// (NSURLRequestUseProtocolCachePolicy) and timeout interval (60
751 /// seconds).
752 ///
753 /// Parameter `URL`: The URL for the request.
754 ///
755 /// Returns: A newly-created and autoreleased NSURLRequest instance.
756 #[unsafe(method(requestWithURL:))]
757 #[unsafe(method_family = none)]
758 pub unsafe fn requestWithURL(url: &NSURL) -> Retained<Self>;
759
760 #[cfg(all(feature = "NSDate", feature = "NSURL"))]
761 /// Allocates and initializes a NSURLRequest with the given
762 /// URL and cache policy.
763 ///
764 /// Parameter `URL`: The URL for the request.
765 ///
766 /// Parameter `cachePolicy`: The cache policy for the request.
767 ///
768 /// Parameter `timeoutInterval`: The timeout interval for the request. See the
769 /// commentary for the
770 /// <tt>
771 /// timeoutInterval
772 /// </tt>
773 /// for more information on
774 /// timeout intervals.
775 ///
776 /// Returns: A newly-created and autoreleased NSURLRequest instance.
777 #[unsafe(method(requestWithURL:cachePolicy:timeoutInterval:))]
778 #[unsafe(method_family = none)]
779 pub unsafe fn requestWithURL_cachePolicy_timeoutInterval(
780 url: &NSURL,
781 cache_policy: NSURLRequestCachePolicy,
782 timeout_interval: NSTimeInterval,
783 ) -> Retained<Self>;
784
785 #[cfg(feature = "NSURL")]
786 /// Initializes an NSURLRequest with the given URL.
787 ///
788 /// Default values are used for cache policy
789 /// (NSURLRequestUseProtocolCachePolicy) and timeout interval (60
790 /// seconds).
791 ///
792 /// Parameter `URL`: The URL for the request.
793 ///
794 /// Returns: An initialized NSURLRequest.
795 #[unsafe(method(initWithURL:))]
796 #[unsafe(method_family = init)]
797 pub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>;
798
799 #[cfg(all(feature = "NSDate", feature = "NSURL"))]
800 /// Initializes an NSURLRequest with the given URL and
801 /// cache policy.
802 ///
803 /// This is the designated initializer for the
804 /// NSURLRequest class.
805 ///
806 /// Parameter `URL`: The URL for the request.
807 ///
808 /// Parameter `cachePolicy`: The cache policy for the request.
809 ///
810 /// Parameter `timeoutInterval`: The timeout interval for the request. See the
811 /// commentary for the
812 /// <tt>
813 /// timeoutInterval
814 /// </tt>
815 /// for more information on
816 /// timeout intervals.
817 ///
818 /// Returns: An initialized NSURLRequest.
819 #[unsafe(method(initWithURL:cachePolicy:timeoutInterval:))]
820 #[unsafe(method_family = init)]
821 pub unsafe fn initWithURL_cachePolicy_timeoutInterval(
822 this: Allocated<Self>,
823 url: &NSURL,
824 cache_policy: NSURLRequestCachePolicy,
825 timeout_interval: NSTimeInterval,
826 ) -> Retained<Self>;
827 );
828}
829
830/// Methods declared on superclass `NSObject`.
831impl NSMutableURLRequest {
832 extern_methods!(
833 #[unsafe(method(init))]
834 #[unsafe(method_family = init)]
835 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
836
837 #[unsafe(method(new))]
838 #[unsafe(method_family = new)]
839 pub unsafe fn new() -> Retained<Self>;
840 );
841}
842
843/// NSHTTPURLRequest.
844/// The NSHTTPURLRequest on NSURLRequest provides methods for accessing
845/// information specific to HTTP protocol requests.
846impl NSURLRequest {
847 extern_methods!(
848 #[cfg(feature = "NSString")]
849 /// Returns the HTTP request method of the receiver.
850 ///
851 /// Returns: the HTTP request method of the receiver.
852 #[unsafe(method(HTTPMethod))]
853 #[unsafe(method_family = none)]
854 pub unsafe fn HTTPMethod(&self) -> Option<Retained<NSString>>;
855
856 #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
857 /// Returns a dictionary containing all the HTTP header fields
858 /// of the receiver.
859 ///
860 /// Returns: a dictionary containing all the HTTP header fields of the
861 /// receiver.
862 #[unsafe(method(allHTTPHeaderFields))]
863 #[unsafe(method_family = none)]
864 pub unsafe fn allHTTPHeaderFields(
865 &self,
866 ) -> Option<Retained<NSDictionary<NSString, NSString>>>;
867
868 #[cfg(feature = "NSString")]
869 /// Returns the value which corresponds to the given header
870 /// field. Note that, in keeping with the HTTP RFC, HTTP header field
871 /// names are case-insensitive.
872 ///
873 /// Parameter `field`: the header field name to use for the lookup
874 /// (case-insensitive).
875 ///
876 /// Returns: the value associated with the given header field, or nil if
877 /// there is no value associated with the given header field.
878 #[unsafe(method(valueForHTTPHeaderField:))]
879 #[unsafe(method_family = none)]
880 pub unsafe fn valueForHTTPHeaderField(
881 &self,
882 field: &NSString,
883 ) -> Option<Retained<NSString>>;
884
885 #[cfg(feature = "NSData")]
886 /// Returns the request body data of the receiver.
887 ///
888 /// This data is sent as the message body of the request, as
889 /// in done in an HTTP POST request.
890 ///
891 /// Returns: The request body data of the receiver.
892 #[unsafe(method(HTTPBody))]
893 #[unsafe(method_family = none)]
894 pub unsafe fn HTTPBody(&self) -> Option<Retained<NSData>>;
895
896 #[cfg(feature = "NSStream")]
897 /// Returns the request body stream of the receiver
898 /// if any has been set
899 ///
900 /// The stream is returned for examination only; it is
901 /// not safe for the caller to manipulate the stream in any way. Also
902 /// note that the HTTPBodyStream and HTTPBody are mutually exclusive - only
903 /// one can be set on a given request. Also note that the body stream is
904 /// preserved across copies, but is LOST when the request is coded via the
905 /// NSCoding protocol
906 ///
907 /// Returns: The request body stream of the receiver.
908 #[unsafe(method(HTTPBodyStream))]
909 #[unsafe(method_family = none)]
910 pub unsafe fn HTTPBodyStream(&self) -> Option<Retained<NSInputStream>>;
911
912 /// Determine whether default cookie handling will happen for
913 /// this request.
914 ///
915 /// NOTE: This value is not used prior to 10.3
916 ///
917 /// Returns: YES if cookies will be sent with and set for this request;
918 /// otherwise NO.
919 #[unsafe(method(HTTPShouldHandleCookies))]
920 #[unsafe(method_family = none)]
921 pub unsafe fn HTTPShouldHandleCookies(&self) -> bool;
922
923 /// Reports whether the receiver is not expected to wait for the
924 /// previous response before transmitting.
925 ///
926 /// Returns: YES if the receiver should transmit before the previous response
927 /// is received. NO if the receiver should wait for the previous response
928 /// before transmitting.
929 #[deprecated = "Only supported in the classic loader, please adopt HTTP/2 and HTTP/3 instead"]
930 #[unsafe(method(HTTPShouldUsePipelining))]
931 #[unsafe(method_family = none)]
932 pub unsafe fn HTTPShouldUsePipelining(&self) -> bool;
933 );
934}
935
936/// NSMutableHTTPURLRequest.
937/// The NSMutableHTTPURLRequest on NSMutableURLRequest provides methods
938/// for configuring information specific to HTTP protocol requests.
939impl NSMutableURLRequest {
940 extern_methods!(
941 #[cfg(feature = "NSString")]
942 /// Sets the HTTP request method of the receiver.
943 #[unsafe(method(HTTPMethod))]
944 #[unsafe(method_family = none)]
945 pub unsafe fn HTTPMethod(&self) -> Retained<NSString>;
946
947 #[cfg(feature = "NSString")]
948 /// Setter for [`HTTPMethod`][Self::HTTPMethod].
949 #[unsafe(method(setHTTPMethod:))]
950 #[unsafe(method_family = none)]
951 pub unsafe fn setHTTPMethod(&self, http_method: &NSString);
952
953 #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
954 /// Sets the HTTP header fields of the receiver to the given
955 /// dictionary.
956 ///
957 /// This method replaces all header fields that may have
958 /// existed before this method call.
959 /// <p>
960 /// Since HTTP header fields must be string values, each object and
961 /// key in the dictionary passed to this method must answer YES when
962 /// sent an
963 /// <tt>
964 /// -isKindOfClass:[NSString class]
965 /// </tt>
966 /// message. If either
967 /// the key or value for a key-value pair answers NO when sent this
968 /// message, the key-value pair is skipped.
969 #[unsafe(method(allHTTPHeaderFields))]
970 #[unsafe(method_family = none)]
971 pub unsafe fn allHTTPHeaderFields(
972 &self,
973 ) -> Option<Retained<NSDictionary<NSString, NSString>>>;
974
975 #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
976 /// Setter for [`allHTTPHeaderFields`][Self::allHTTPHeaderFields].
977 #[unsafe(method(setAllHTTPHeaderFields:))]
978 #[unsafe(method_family = none)]
979 pub unsafe fn setAllHTTPHeaderFields(
980 &self,
981 all_http_header_fields: Option<&NSDictionary<NSString, NSString>>,
982 );
983
984 #[cfg(feature = "NSString")]
985 /// Sets the value of the given HTTP header field.
986 ///
987 /// If a value was previously set for the given header
988 /// field, that value is replaced with the given value. Note that, in
989 /// keeping with the HTTP RFC, HTTP header field names are
990 /// case-insensitive.
991 ///
992 /// Parameter `value`: the header field value.
993 ///
994 /// Parameter `field`: the header field name (case-insensitive).
995 #[unsafe(method(setValue:forHTTPHeaderField:))]
996 #[unsafe(method_family = none)]
997 pub unsafe fn setValue_forHTTPHeaderField(
998 &self,
999 value: Option<&NSString>,
1000 field: &NSString,
1001 );
1002
1003 #[cfg(feature = "NSString")]
1004 /// Adds an HTTP header field in the current header
1005 /// dictionary.
1006 ///
1007 /// This method provides a way to add values to header
1008 /// fields incrementally. If a value was previously set for the given
1009 /// header field, the given value is appended to the previously-existing
1010 /// value. The appropriate field delimiter, a comma in the case of HTTP,
1011 /// is added by the implementation, and should not be added to the given
1012 /// value by the caller. Note that, in keeping with the HTTP RFC, HTTP
1013 /// header field names are case-insensitive.
1014 ///
1015 /// Parameter `value`: the header field value.
1016 ///
1017 /// Parameter `field`: the header field name (case-insensitive).
1018 #[unsafe(method(addValue:forHTTPHeaderField:))]
1019 #[unsafe(method_family = none)]
1020 pub unsafe fn addValue_forHTTPHeaderField(&self, value: &NSString, field: &NSString);
1021
1022 #[cfg(feature = "NSData")]
1023 /// Sets the request body data of the receiver.
1024 ///
1025 /// This data is sent as the message body of the request, as
1026 /// in done in an HTTP POST request.
1027 #[unsafe(method(HTTPBody))]
1028 #[unsafe(method_family = none)]
1029 pub unsafe fn HTTPBody(&self) -> Option<Retained<NSData>>;
1030
1031 #[cfg(feature = "NSData")]
1032 /// Setter for [`HTTPBody`][Self::HTTPBody].
1033 #[unsafe(method(setHTTPBody:))]
1034 #[unsafe(method_family = none)]
1035 pub unsafe fn setHTTPBody(&self, http_body: Option<&NSData>);
1036
1037 #[cfg(feature = "NSStream")]
1038 /// Sets the request body to be the contents of the given stream.
1039 ///
1040 /// The provided stream should be unopened; the request will take
1041 /// over the stream's delegate. The entire stream's contents will be
1042 /// transmitted as the HTTP body of the request. Note that the body stream
1043 /// and the body data (set by setHTTPBody:, above) are mutually exclusive
1044 /// - setting one will clear the other.
1045 #[unsafe(method(HTTPBodyStream))]
1046 #[unsafe(method_family = none)]
1047 pub unsafe fn HTTPBodyStream(&self) -> Option<Retained<NSInputStream>>;
1048
1049 #[cfg(feature = "NSStream")]
1050 /// Setter for [`HTTPBodyStream`][Self::HTTPBodyStream].
1051 #[unsafe(method(setHTTPBodyStream:))]
1052 #[unsafe(method_family = none)]
1053 pub unsafe fn setHTTPBodyStream(&self, http_body_stream: Option<&NSInputStream>);
1054
1055 /// Decide whether default cookie handling will happen for
1056 /// this request (YES if cookies should be sent with and set for this request;
1057 /// otherwise NO).
1058 ///
1059 /// The default is YES - in other words, cookies are sent from and
1060 /// stored to the cookie manager by default.
1061 /// NOTE: In releases prior to 10.3, this value is ignored
1062 #[unsafe(method(HTTPShouldHandleCookies))]
1063 #[unsafe(method_family = none)]
1064 pub unsafe fn HTTPShouldHandleCookies(&self) -> bool;
1065
1066 /// Setter for [`HTTPShouldHandleCookies`][Self::HTTPShouldHandleCookies].
1067 #[unsafe(method(setHTTPShouldHandleCookies:))]
1068 #[unsafe(method_family = none)]
1069 pub unsafe fn setHTTPShouldHandleCookies(&self, http_should_handle_cookies: bool);
1070
1071 /// Sets whether the request should not wait for the previous response
1072 /// before transmitting (YES if the receiver should transmit before the previous response is
1073 /// received. NO to wait for the previous response before transmitting)
1074 ///
1075 /// Calling this method with a YES value does not guarantee HTTP
1076 /// pipelining behavior. This method may have no effect if an HTTP proxy is
1077 /// configured, or if the HTTP request uses an unsafe request method (e.g., POST
1078 /// requests will not pipeline). Pipelining behavior also may not begin until
1079 /// the second request on a given TCP connection. There may be other situations
1080 /// where pipelining does not occur even though YES was set.
1081 /// HTTP 1.1 allows the client to send multiple requests to the server without
1082 /// waiting for a response. Though HTTP 1.1 requires support for pipelining,
1083 /// some servers report themselves as being HTTP 1.1 but do not support
1084 /// pipelining (disconnecting, sending resources misordered, omitting part of
1085 /// a resource, etc.).
1086 #[deprecated = "Only supported in the classic loader, please adopt HTTP/2 and HTTP/3 instead"]
1087 #[unsafe(method(HTTPShouldUsePipelining))]
1088 #[unsafe(method_family = none)]
1089 pub unsafe fn HTTPShouldUsePipelining(&self) -> bool;
1090
1091 /// Setter for [`HTTPShouldUsePipelining`][Self::HTTPShouldUsePipelining].
1092 #[deprecated = "Only supported in the classic loader, please adopt HTTP/2 and HTTP/3 instead"]
1093 #[unsafe(method(setHTTPShouldUsePipelining:))]
1094 #[unsafe(method_family = none)]
1095 pub unsafe fn setHTTPShouldUsePipelining(&self, http_should_use_pipelining: bool);
1096 );
1097}