1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use objc2::__framework_prelude::*;

use crate::*;

extern_protocol!(
    pub unsafe trait NSURLProtocolClient: NSObjectProtocol {
        #[cfg(all(feature = "NSURLRequest", feature = "NSURLResponse"))]
        #[method(URLProtocol:wasRedirectedToRequest:redirectResponse:)]
        unsafe fn URLProtocol_wasRedirectedToRequest_redirectResponse(
            &self,
            protocol: &NSURLProtocol,
            request: &NSURLRequest,
            redirect_response: &NSURLResponse,
        );

        #[cfg(feature = "NSURLCache")]
        #[method(URLProtocol:cachedResponseIsValid:)]
        unsafe fn URLProtocol_cachedResponseIsValid(
            &self,
            protocol: &NSURLProtocol,
            cached_response: &NSCachedURLResponse,
        );

        #[cfg(all(feature = "NSURLCache", feature = "NSURLResponse"))]
        #[method(URLProtocol:didReceiveResponse:cacheStoragePolicy:)]
        unsafe fn URLProtocol_didReceiveResponse_cacheStoragePolicy(
            &self,
            protocol: &NSURLProtocol,
            response: &NSURLResponse,
            policy: NSURLCacheStoragePolicy,
        );

        #[cfg(feature = "NSData")]
        #[method(URLProtocol:didLoadData:)]
        unsafe fn URLProtocol_didLoadData(&self, protocol: &NSURLProtocol, data: &NSData);

        #[method(URLProtocolDidFinishLoading:)]
        unsafe fn URLProtocolDidFinishLoading(&self, protocol: &NSURLProtocol);

        #[cfg(feature = "NSError")]
        #[method(URLProtocol:didFailWithError:)]
        unsafe fn URLProtocol_didFailWithError(&self, protocol: &NSURLProtocol, error: &NSError);

        #[cfg(feature = "NSURLAuthenticationChallenge")]
        #[method(URLProtocol:didReceiveAuthenticationChallenge:)]
        unsafe fn URLProtocol_didReceiveAuthenticationChallenge(
            &self,
            protocol: &NSURLProtocol,
            challenge: &NSURLAuthenticationChallenge,
        );

        #[cfg(feature = "NSURLAuthenticationChallenge")]
        #[method(URLProtocol:didCancelAuthenticationChallenge:)]
        unsafe fn URLProtocol_didCancelAuthenticationChallenge(
            &self,
            protocol: &NSURLProtocol,
            challenge: &NSURLAuthenticationChallenge,
        );
    }

    unsafe impl ProtocolType for dyn NSURLProtocolClient {}
);

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSURLProtocol;

    unsafe impl ClassType for NSURLProtocol {
        type Super = NSObject;
        type Mutability = InteriorMutable;
    }
);

unsafe impl NSObjectProtocol for NSURLProtocol {}

extern_methods!(
    unsafe impl NSURLProtocol {
        #[cfg(all(feature = "NSURLCache", feature = "NSURLRequest"))]
        #[method_id(@__retain_semantics Init initWithRequest:cachedResponse:client:)]
        pub unsafe fn initWithRequest_cachedResponse_client(
            this: Allocated<Self>,
            request: &NSURLRequest,
            cached_response: Option<&NSCachedURLResponse>,
            client: Option<&ProtocolObject<dyn NSURLProtocolClient>>,
        ) -> Retained<Self>;

        #[method_id(@__retain_semantics Other client)]
        pub unsafe fn client(&self) -> Option<Retained<ProtocolObject<dyn NSURLProtocolClient>>>;

        #[cfg(feature = "NSURLRequest")]
        #[method_id(@__retain_semantics Other request)]
        pub unsafe fn request(&self) -> Retained<NSURLRequest>;

        #[cfg(feature = "NSURLCache")]
        #[method_id(@__retain_semantics Other cachedResponse)]
        pub unsafe fn cachedResponse(&self) -> Option<Retained<NSCachedURLResponse>>;

        #[cfg(feature = "NSURLRequest")]
        #[method(canInitWithRequest:)]
        pub unsafe fn canInitWithRequest(request: &NSURLRequest) -> bool;

        #[cfg(feature = "NSURLRequest")]
        #[method_id(@__retain_semantics Other canonicalRequestForRequest:)]
        pub unsafe fn canonicalRequestForRequest(request: &NSURLRequest) -> Retained<NSURLRequest>;

        #[cfg(feature = "NSURLRequest")]
        #[method(requestIsCacheEquivalent:toRequest:)]
        pub unsafe fn requestIsCacheEquivalent_toRequest(
            a: &NSURLRequest,
            b: &NSURLRequest,
        ) -> bool;

        #[method(startLoading)]
        pub unsafe fn startLoading(&self);

        #[method(stopLoading)]
        pub unsafe fn stopLoading(&self);

        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
        #[method_id(@__retain_semantics Other propertyForKey:inRequest:)]
        pub unsafe fn propertyForKey_inRequest(
            key: &NSString,
            request: &NSURLRequest,
        ) -> Option<Retained<AnyObject>>;

        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
        #[method(setProperty:forKey:inRequest:)]
        pub unsafe fn setProperty_forKey_inRequest(
            value: &AnyObject,
            key: &NSString,
            request: &NSMutableURLRequest,
        );

        #[cfg(all(feature = "NSString", feature = "NSURLRequest"))]
        #[method(removePropertyForKey:inRequest:)]
        pub unsafe fn removePropertyForKey_inRequest(key: &NSString, request: &NSMutableURLRequest);

        #[method(registerClass:)]
        pub unsafe fn registerClass(protocol_class: &AnyClass) -> bool;

        #[method(unregisterClass:)]
        pub unsafe fn unregisterClass(protocol_class: &AnyClass);
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl NSURLProtocol {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new() -> Retained<Self>;
    }
);

extern_methods!(
    /// NSURLSessionTaskAdditions
    unsafe impl NSURLProtocol {
        #[cfg(feature = "NSURLSession")]
        #[method(canInitWithTask:)]
        pub unsafe fn canInitWithTask(task: &NSURLSessionTask) -> bool;

        #[cfg(all(feature = "NSURLCache", feature = "NSURLSession"))]
        #[method_id(@__retain_semantics Init initWithTask:cachedResponse:client:)]
        pub unsafe fn initWithTask_cachedResponse_client(
            this: Allocated<Self>,
            task: &NSURLSessionTask,
            cached_response: Option<&NSCachedURLResponse>,
            client: Option<&ProtocolObject<dyn NSURLProtocolClient>>,
        ) -> Retained<Self>;

        #[cfg(feature = "NSURLSession")]
        #[method_id(@__retain_semantics Other task)]
        pub unsafe fn task(&self) -> Option<Retained<NSURLSessionTask>>;
    }
);