objc2_foundation/generated/
NSURLResponse.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_class!(
10    /// An NSURLResponse object represents a URL load response in a
11    /// manner independent of protocol and URL scheme.
12    ///
13    ///
14    /// NSURLResponse encapsulates the metadata associated
15    /// with a URL load. Note that NSURLResponse objects do not contain
16    /// the actual bytes representing the content of a URL. See
17    /// NSURLConnection and NSURLConnectionDelegate for more information
18    /// about receiving the content data for a URL load.
19    ///
20    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlresponse?language=objc)
21    #[unsafe(super(NSObject))]
22    #[derive(Debug, PartialEq, Eq, Hash)]
23    pub struct NSURLResponse;
24);
25
26unsafe impl Send for NSURLResponse {}
27
28unsafe impl Sync for NSURLResponse {}
29
30#[cfg(feature = "NSObject")]
31unsafe impl NSCoding for NSURLResponse {}
32
33#[cfg(feature = "NSObject")]
34unsafe impl NSCopying for NSURLResponse {}
35
36#[cfg(feature = "NSObject")]
37unsafe impl CopyingHelper for NSURLResponse {
38    type Result = Self;
39}
40
41unsafe impl NSObjectProtocol for NSURLResponse {}
42
43#[cfg(feature = "NSObject")]
44unsafe impl NSSecureCoding for NSURLResponse {}
45
46impl NSURLResponse {
47    extern_methods!(
48        #[cfg(all(feature = "NSString", feature = "NSURL"))]
49        /// Initialize an NSURLResponse with the provided values.
50        ///
51        /// Parameter `URL`: the URL
52        ///
53        /// Parameter `MIMEType`: the MIME content type of the response
54        ///
55        /// Parameter `length`: the expected content length of the associated data
56        ///
57        /// Parameter `name`: the name of the text encoding for the associated data, if applicable, else nil
58        ///
59        /// Returns: The initialized NSURLResponse.
60        ///
61        /// This is the designated initializer for NSURLResponse.
62        #[unsafe(method(initWithURL:MIMEType:expectedContentLength:textEncodingName:))]
63        #[unsafe(method_family = init)]
64        pub unsafe fn initWithURL_MIMEType_expectedContentLength_textEncodingName(
65            this: Allocated<Self>,
66            url: &NSURL,
67            mime_type: Option<&NSString>,
68            length: NSInteger,
69            name: Option<&NSString>,
70        ) -> Retained<Self>;
71
72        #[cfg(feature = "NSURL")]
73        /// Returns the URL of the receiver.
74        ///
75        /// Returns: The URL of the receiver.
76        #[unsafe(method(URL))]
77        #[unsafe(method_family = none)]
78        pub unsafe fn URL(&self) -> Option<Retained<NSURL>>;
79
80        #[cfg(feature = "NSString")]
81        /// Returns the MIME type of the receiver.
82        ///
83        /// The MIME type is based on the information provided
84        /// from an origin source. However, that value may be changed or
85        /// corrected by a protocol implementation if it can be determined
86        /// that the origin server or source reported the information
87        /// incorrectly or imprecisely. An attempt to guess the MIME type may
88        /// be made if the origin source did not report any such information.
89        ///
90        /// Returns: The MIME type of the receiver.
91        #[unsafe(method(MIMEType))]
92        #[unsafe(method_family = none)]
93        pub unsafe fn MIMEType(&self) -> Option<Retained<NSString>>;
94
95        /// Returns the expected content length of the receiver.
96        ///
97        /// Some protocol implementations report a content length
98        /// as part of delivering load metadata, but not all protocols
99        /// guarantee the amount of data that will be delivered in actuality.
100        /// Hence, this method returns an expected amount. Clients should use
101        /// this value as an advisory, and should be prepared to deal with
102        /// either more or less data.
103        ///
104        /// Returns: The expected content length of the receiver, or -1 if
105        /// there is no expectation that can be arrived at regarding expected
106        /// content length.
107        #[unsafe(method(expectedContentLength))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn expectedContentLength(&self) -> c_longlong;
110
111        #[cfg(feature = "NSString")]
112        /// Returns the name of the text encoding of the receiver.
113        ///
114        /// This name will be the actual string reported by the
115        /// origin source during the course of performing a protocol-specific
116        /// URL load. Clients can inspect this string and convert it to an
117        /// NSStringEncoding or CFStringEncoding using the methods and
118        /// functions made available in the appropriate framework.
119        ///
120        /// Returns: The name of the text encoding of the receiver, or nil if no
121        /// text encoding was specified.
122        #[unsafe(method(textEncodingName))]
123        #[unsafe(method_family = none)]
124        pub unsafe fn textEncodingName(&self) -> Option<Retained<NSString>>;
125
126        #[cfg(feature = "NSString")]
127        /// Returns a suggested filename if the resource were saved to disk.
128        ///
129        /// The method first checks if the server has specified a filename using the
130        /// content disposition header. If no valid filename is specified using that mechanism,
131        /// this method checks the last path component of the URL. If no valid filename can be
132        /// obtained using the last path component, this method uses the URL's host as the filename.
133        /// If the URL's host can't be converted to a valid filename, the filename "unknown" is used.
134        /// In most cases, this method appends the proper file extension based on the MIME type.
135        /// This method always returns a valid filename.
136        ///
137        /// Returns: A suggested filename to use if saving the resource to disk.
138        #[unsafe(method(suggestedFilename))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn suggestedFilename(&self) -> Option<Retained<NSString>>;
141    );
142}
143
144/// Methods declared on superclass `NSObject`.
145impl NSURLResponse {
146    extern_methods!(
147        #[unsafe(method(init))]
148        #[unsafe(method_family = init)]
149        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
150
151        #[unsafe(method(new))]
152        #[unsafe(method_family = new)]
153        pub unsafe fn new() -> Retained<Self>;
154    );
155}
156
157extern_class!(
158    /// An NSHTTPURLResponse object represents a response to an
159    /// HTTP URL load. It is a specialization of NSURLResponse which
160    /// provides conveniences for accessing information specific to HTTP
161    /// protocol responses.
162    ///
163    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshttpurlresponse?language=objc)
164    #[unsafe(super(NSURLResponse, NSObject))]
165    #[derive(Debug, PartialEq, Eq, Hash)]
166    pub struct NSHTTPURLResponse;
167);
168
169unsafe impl Send for NSHTTPURLResponse {}
170
171unsafe impl Sync for NSHTTPURLResponse {}
172
173#[cfg(feature = "NSObject")]
174unsafe impl NSCoding for NSHTTPURLResponse {}
175
176#[cfg(feature = "NSObject")]
177unsafe impl NSCopying for NSHTTPURLResponse {}
178
179#[cfg(feature = "NSObject")]
180unsafe impl CopyingHelper for NSHTTPURLResponse {
181    type Result = Self;
182}
183
184unsafe impl NSObjectProtocol for NSHTTPURLResponse {}
185
186#[cfg(feature = "NSObject")]
187unsafe impl NSSecureCoding for NSHTTPURLResponse {}
188
189impl NSHTTPURLResponse {
190    extern_methods!(
191        #[cfg(all(feature = "NSDictionary", feature = "NSString", feature = "NSURL"))]
192        /// initializer for NSHTTPURLResponse objects.
193        ///
194        /// Parameter `url`: the URL from which the response was generated.
195        ///
196        /// Parameter `statusCode`: an HTTP status code.
197        ///
198        /// Parameter `HTTPVersion`: The version of the HTTP response as represented by the server.  This is typically represented as "HTTP/1.1".
199        ///
200        /// Parameter `headerFields`: A dictionary representing the header keys and values of the server response.
201        ///
202        /// Returns: the instance of the object, or NULL if an error occurred during initialization.
203        ///
204        /// This API was introduced in Mac OS X 10.7.2 and iOS 5.0 and is not available prior to those releases.
205        #[unsafe(method(initWithURL:statusCode:HTTPVersion:headerFields:))]
206        #[unsafe(method_family = init)]
207        pub unsafe fn initWithURL_statusCode_HTTPVersion_headerFields(
208            this: Allocated<Self>,
209            url: &NSURL,
210            status_code: NSInteger,
211            http_version: Option<&NSString>,
212            header_fields: Option<&NSDictionary<NSString, NSString>>,
213        ) -> Option<Retained<Self>>;
214
215        /// Returns the HTTP status code of the receiver.
216        ///
217        /// Returns: The HTTP status code of the receiver.
218        #[unsafe(method(statusCode))]
219        #[unsafe(method_family = none)]
220        pub unsafe fn statusCode(&self) -> NSInteger;
221
222        #[cfg(feature = "NSDictionary")]
223        /// Returns a dictionary containing all the HTTP header fields
224        /// of the receiver.
225        ///
226        /// By examining this header dictionary, clients can see
227        /// the "raw" header information which was reported to the protocol
228        /// implementation by the HTTP server. This may be of use to
229        /// sophisticated or special-purpose HTTP clients.
230        ///
231        /// Returns: A dictionary containing all the HTTP header fields of the
232        /// receiver.
233        #[unsafe(method(allHeaderFields))]
234        #[unsafe(method_family = none)]
235        pub unsafe fn allHeaderFields(&self) -> Retained<NSDictionary>;
236
237        #[cfg(feature = "NSString")]
238        /// Returns the value which corresponds to the given header
239        /// field. Note that, in keeping with the HTTP RFC, HTTP header field
240        /// names are case-insensitive.
241        ///
242        /// Parameter `field`: the header field name to use for the lookup
243        /// (case-insensitive).
244        ///
245        /// Returns: the value associated with the given header field, or nil if
246        /// there is no value associated with the given header field.
247        #[unsafe(method(valueForHTTPHeaderField:))]
248        #[unsafe(method_family = none)]
249        pub unsafe fn valueForHTTPHeaderField(
250            &self,
251            field: &NSString,
252        ) -> Option<Retained<NSString>>;
253
254        #[cfg(feature = "NSString")]
255        /// Convenience method which returns a localized string
256        /// corresponding to the status code for this response.
257        ///
258        /// Parameter `statusCode`: the status code to use to produce a localized string.
259        ///
260        /// Returns: A localized string corresponding to the given status code.
261        #[unsafe(method(localizedStringForStatusCode:))]
262        #[unsafe(method_family = none)]
263        pub unsafe fn localizedStringForStatusCode(status_code: NSInteger) -> Retained<NSString>;
264    );
265}
266
267/// Methods declared on superclass `NSURLResponse`.
268impl NSHTTPURLResponse {
269    extern_methods!(
270        #[cfg(all(feature = "NSString", feature = "NSURL"))]
271        /// Initialize an NSURLResponse with the provided values.
272        ///
273        /// Parameter `URL`: the URL
274        ///
275        /// Parameter `MIMEType`: the MIME content type of the response
276        ///
277        /// Parameter `length`: the expected content length of the associated data
278        ///
279        /// Parameter `name`: the name of the text encoding for the associated data, if applicable, else nil
280        ///
281        /// Returns: The initialized NSURLResponse.
282        ///
283        /// This is the designated initializer for NSURLResponse.
284        #[unsafe(method(initWithURL:MIMEType:expectedContentLength:textEncodingName:))]
285        #[unsafe(method_family = init)]
286        pub unsafe fn initWithURL_MIMEType_expectedContentLength_textEncodingName(
287            this: Allocated<Self>,
288            url: &NSURL,
289            mime_type: Option<&NSString>,
290            length: NSInteger,
291            name: Option<&NSString>,
292        ) -> Retained<Self>;
293    );
294}
295
296/// Methods declared on superclass `NSObject`.
297impl NSHTTPURLResponse {
298    extern_methods!(
299        #[unsafe(method(init))]
300        #[unsafe(method_family = init)]
301        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
302
303        #[unsafe(method(new))]
304        #[unsafe(method_family = new)]
305        pub unsafe fn new() -> Retained<Self>;
306    );
307}