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 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 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 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 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 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 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 fn init(this: Allocated<Self>) -> Retained<Self>;
158
159        #[unsafe(method(new))]
160        #[unsafe(method_family = new)]
161        pub fn new() -> Retained<Self>;
162    );
163}
164
165impl DefaultRetained for NSURLResponse {
166    #[inline]
167    fn default_retained() -> Retained<Self> {
168        Self::new()
169    }
170}
171
172extern_class!(
173    /// An NSHTTPURLResponse object represents a response to an
174    /// HTTP URL load. It is a specialization of NSURLResponse which
175    /// provides conveniences for accessing information specific to HTTP
176    /// protocol responses.
177    ///
178    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshttpurlresponse?language=objc)
179    #[unsafe(super(NSURLResponse, NSObject))]
180    #[derive(Debug, PartialEq, Eq, Hash)]
181    pub struct NSHTTPURLResponse;
182);
183
184unsafe impl Send for NSHTTPURLResponse {}
185
186unsafe impl Sync for NSHTTPURLResponse {}
187
188#[cfg(feature = "NSObject")]
189extern_conformance!(
190    unsafe impl NSCoding for NSHTTPURLResponse {}
191);
192
193#[cfg(feature = "NSObject")]
194extern_conformance!(
195    unsafe impl NSCopying for NSHTTPURLResponse {}
196);
197
198#[cfg(feature = "NSObject")]
199unsafe impl CopyingHelper for NSHTTPURLResponse {
200    type Result = Self;
201}
202
203extern_conformance!(
204    unsafe impl NSObjectProtocol for NSHTTPURLResponse {}
205);
206
207#[cfg(feature = "NSObject")]
208extern_conformance!(
209    unsafe impl NSSecureCoding for NSHTTPURLResponse {}
210);
211
212impl NSHTTPURLResponse {
213    extern_methods!(
214        #[cfg(all(feature = "NSDictionary", feature = "NSString", feature = "NSURL"))]
215        /// initializer for NSHTTPURLResponse objects.
216        ///
217        /// Parameter `url`: the URL from which the response was generated.
218        ///
219        /// Parameter `statusCode`: an HTTP status code.
220        ///
221        /// Parameter `HTTPVersion`: The version of the HTTP response as represented by the server.  This is typically represented as "HTTP/1.1".
222        ///
223        /// Parameter `headerFields`: A dictionary representing the header keys and values of the server response.
224        ///
225        /// Returns: the instance of the object, or NULL if an error occurred during initialization.
226        ///
227        /// This API was introduced in Mac OS X 10.7.2 and iOS 5.0 and is not available prior to those releases.
228        #[unsafe(method(initWithURL:statusCode:HTTPVersion:headerFields:))]
229        #[unsafe(method_family = init)]
230        pub fn initWithURL_statusCode_HTTPVersion_headerFields(
231            this: Allocated<Self>,
232            url: &NSURL,
233            status_code: NSInteger,
234            http_version: Option<&NSString>,
235            header_fields: Option<&NSDictionary<NSString, NSString>>,
236        ) -> Option<Retained<Self>>;
237
238        /// Returns the HTTP status code of the receiver.
239        ///
240        /// Returns: The HTTP status code of the receiver.
241        #[unsafe(method(statusCode))]
242        #[unsafe(method_family = none)]
243        pub fn statusCode(&self) -> NSInteger;
244
245        #[cfg(feature = "NSDictionary")]
246        /// Returns a dictionary containing all the HTTP header fields
247        /// of the receiver.
248        ///
249        /// By examining this header dictionary, clients can see
250        /// the "raw" header information which was reported to the protocol
251        /// implementation by the HTTP server. This may be of use to
252        /// sophisticated or special-purpose HTTP clients.
253        ///
254        /// Returns: A dictionary containing all the HTTP header fields of the
255        /// receiver.
256        #[unsafe(method(allHeaderFields))]
257        #[unsafe(method_family = none)]
258        pub fn allHeaderFields(&self) -> Retained<NSDictionary>;
259
260        #[cfg(feature = "NSString")]
261        /// Returns the value which corresponds to the given header
262        /// field. Note that, in keeping with the HTTP RFC, HTTP header field
263        /// names are case-insensitive.
264        ///
265        /// Parameter `field`: the header field name to use for the lookup
266        /// (case-insensitive).
267        ///
268        /// Returns: the value associated with the given header field, or nil if
269        /// there is no value associated with the given header field.
270        #[unsafe(method(valueForHTTPHeaderField:))]
271        #[unsafe(method_family = none)]
272        pub fn valueForHTTPHeaderField(&self, field: &NSString) -> Option<Retained<NSString>>;
273
274        #[cfg(feature = "NSString")]
275        /// Convenience method which returns a localized string
276        /// corresponding to the status code for this response.
277        ///
278        /// Parameter `statusCode`: the status code to use to produce a localized string.
279        ///
280        /// Returns: A localized string corresponding to the given status code.
281        #[unsafe(method(localizedStringForStatusCode:))]
282        #[unsafe(method_family = none)]
283        pub fn localizedStringForStatusCode(status_code: NSInteger) -> Retained<NSString>;
284    );
285}
286
287/// Methods declared on superclass `NSURLResponse`.
288impl NSHTTPURLResponse {
289    extern_methods!(
290        #[cfg(all(feature = "NSString", feature = "NSURL"))]
291        /// Initialize an NSURLResponse with the provided values.
292        ///
293        /// Parameter `URL`: the URL
294        ///
295        /// Parameter `MIMEType`: the MIME content type of the response
296        ///
297        /// Parameter `length`: the expected content length of the associated data
298        ///
299        /// Parameter `name`: the name of the text encoding for the associated data, if applicable, else nil
300        ///
301        /// Returns: The initialized NSURLResponse.
302        ///
303        /// This is the designated initializer for NSURLResponse.
304        #[unsafe(method(initWithURL:MIMEType:expectedContentLength:textEncodingName:))]
305        #[unsafe(method_family = init)]
306        pub fn initWithURL_MIMEType_expectedContentLength_textEncodingName(
307            this: Allocated<Self>,
308            url: &NSURL,
309            mime_type: Option<&NSString>,
310            length: NSInteger,
311            name: Option<&NSString>,
312        ) -> Retained<Self>;
313    );
314}
315
316/// Methods declared on superclass `NSObject`.
317impl NSHTTPURLResponse {
318    extern_methods!(
319        #[unsafe(method(init))]
320        #[unsafe(method_family = init)]
321        pub fn init(this: Allocated<Self>) -> Retained<Self>;
322
323        #[unsafe(method(new))]
324        #[unsafe(method_family = new)]
325        pub fn new() -> Retained<Self>;
326    );
327}
328
329impl DefaultRetained for NSHTTPURLResponse {
330    #[inline]
331    fn default_retained() -> Retained<Self> {
332        Self::new()
333    }
334}