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