@@ -132,6 +132,7 @@ protocol ApiRequest {
132132 /// - headers: HTTP headers
133133 /// - encodable: Codable object to encode as JSON body
134134 /// - timeout: Request timeout in seconds
135+ /// - authorization: If we should set authorization header
135136 /// - Throws: Encoding errors if encodable cannot be serialized
136137 init (
137138 caller: ApiCaller ,
@@ -140,7 +141,8 @@ protocol ApiRequest {
140141 queryItems: [ URLQueryItem ] ,
141142 headers: Headers ,
142143 encodable: Encodable ,
143- timeout: TimeInterval
144+ timeout: TimeInterval ,
145+ authorization: Bool
144146 ) throws
145147
146148 /// Initializer for requests with raw Data body
@@ -152,14 +154,16 @@ protocol ApiRequest {
152154 /// - headers: HTTP headers
153155 /// - body: Raw data for request body
154156 /// - timeout: Request timeout in seconds
157+ /// - authorization: If we should set authorization header
155158 init (
156159 caller: ApiCaller ,
157160 method: ApiMethod ? ,
158161 endpoint: ApiEndpoint ,
159162 queryItems: [ URLQueryItem ] ,
160163 headers: Headers ,
161164 body: Data ? ,
162- timeout: TimeInterval
165+ timeout: TimeInterval ,
166+ authorization: Bool
163167 )
164168
165169 /// Initializer for form-encoded requests
@@ -171,14 +175,16 @@ protocol ApiRequest {
171175 /// - headers: HTTP headers
172176 /// - form: Form data dictionary
173177 /// - timeout: Request timeout in seconds
178+ /// - authorization: If we should set authorization header
174179 init (
175180 caller: ApiCaller ,
176181 method: ApiMethod ? ,
177182 endpoint: ApiEndpoint ,
178183 queryItems: [ URLQueryItem ] ,
179184 headers: Headers ,
180185 form: Form ,
181- timeout: TimeInterval
186+ timeout: TimeInterval ,
187+ authorization: Bool
182188 )
183189
184190 /// The configured URLRequest ready for execution
@@ -291,6 +297,8 @@ struct ApiRequestImpl: ApiRequest {
291297 let body : Data ?
292298 /// Request timeout in seconds
293299 let timeout : TimeInterval
300+ /// If we should set authorization header
301+ let authorization : Bool
294302
295303 /// Character set used for form data encoding
296304 private static let formCharset : CharacterSet = {
@@ -310,7 +318,8 @@ struct ApiRequestImpl: ApiRequest {
310318 queryItems: [ URLQueryItem ] ,
311319 headers: Headers ,
312320 encodable: Encodable ,
313- timeout: TimeInterval
321+ timeout: TimeInterval ,
322+ authorization: Bool
314323 ) throws {
315324 var headers = headers
316325 if headers [ " Content-type " ] == nil {
@@ -326,6 +335,7 @@ struct ApiRequestImpl: ApiRequest {
326335 self . headers = headers
327336 body = try JSONEncoders . default. encode ( encodable)
328337 self . timeout = timeout
338+ self . authorization = authorization
329339 }
330340
331341 init (
@@ -335,7 +345,8 @@ struct ApiRequestImpl: ApiRequest {
335345 queryItems: [ URLQueryItem ] ,
336346 headers: Headers ,
337347 body: Data ? ,
338- timeout: TimeInterval
348+ timeout: TimeInterval ,
349+ authorization: Bool
339350 ) {
340351 var headers = headers
341352 if headers [ " Content-type " ] == nil {
@@ -351,16 +362,17 @@ struct ApiRequestImpl: ApiRequest {
351362 self . headers = headers
352363 self . body = body
353364 self . timeout = timeout
365+ self . authorization = authorization
354366 }
355367
356- init (
357- caller : ApiCaller ,
358- method : ApiMethod ? ,
359- endpoint : ApiEndpoint ,
360- queryItems : [ URLQueryItem ] ,
361- headers : Headers ,
362- form : Form ,
363- timeout : TimeInterval
368+ init ( caller : ApiCaller ,
369+ method : ApiMethod ? ,
370+ endpoint : ApiEndpoint ,
371+ queryItems : [ URLQueryItem ] ,
372+ headers : Headers ,
373+ form : Form ,
374+ timeout : TimeInterval ,
375+ authorization : Bool
364376 ) {
365377 var headers = Self . commonFormHeaders
366378 headers [ " User-Agent " ] = caller. configuration. userAgent
@@ -378,6 +390,7 @@ struct ApiRequestImpl: ApiRequest {
378390 self . headers = headers
379391 body = formData
380392 self . timeout = timeout
393+ self . authorization = authorization
381394 }
382395
383396 var urlRequest : URLRequest {
@@ -389,7 +402,7 @@ struct ApiRequestImpl: ApiRequest {
389402 var request = URLRequest ( url: url, cachePolicy: . reloadIgnoringCacheData, timeoutInterval: timeout)
390403 request. httpMethod = method. rawValue
391404 var headers = self . headers
392- if let authorization = caller. authorization {
405+ if let authorization = caller. authorization, self . authorization {
393406 for (key, value) in authorization. authorizatioHeaders ( for: caller. configuration) {
394407 headers [ key] = value
395408 }
@@ -550,6 +563,7 @@ class ApiRequestProvider: NSObject {
550563 /// - headers: HTTP headers
551564 /// - encodable: Object to encode as JSON body
552565 /// - timeout: Request timeout
566+ /// - authorization: If authorization header should be set
553567 /// - Returns: Configured API request
554568 /// - Throws: Encoding errors
555569 func request(
@@ -558,7 +572,8 @@ class ApiRequestProvider: NSObject {
558572 queryItems: [ URLQueryItem ] = [ ] ,
559573 headers: ApiRequest . Headers = [ : ] ,
560574 encodable: Encodable ,
561- timeout: TimeInterval = ApiDefaultTimeout
575+ timeout: TimeInterval = ApiDefaultTimeout,
576+ authorization: Bool = true
562577 ) throws -> ApiRequest {
563578 try requestType. init (
564579 caller: caller,
@@ -567,7 +582,8 @@ class ApiRequestProvider: NSObject {
567582 queryItems: queryItems,
568583 headers: headers,
569584 encodable: encodable,
570- timeout: timeout
585+ timeout: timeout,
586+ authorization: authorization
571587 )
572588 }
573589
@@ -579,14 +595,16 @@ class ApiRequestProvider: NSObject {
579595 /// - headers: HTTP headers
580596 /// - body: Raw body data
581597 /// - timeout: Request timeout
598+ /// - authorization: If authorization header should be set
582599 /// - Returns: Configured API request
583600 func request(
584601 with method: ApiMethod ? = nil ,
585602 endpoint: ApiEndpoint ,
586603 queryItems: [ URLQueryItem ] = [ ] ,
587604 headers: ApiRequest . Headers = [ : ] ,
588605 body: Data ? = nil ,
589- timeout: TimeInterval = ApiDefaultTimeout
606+ timeout: TimeInterval = ApiDefaultTimeout,
607+ authorization: Bool = true
590608 ) -> ApiRequest {
591609 requestType. init (
592610 caller: caller,
@@ -595,7 +613,8 @@ class ApiRequestProvider: NSObject {
595613 queryItems: queryItems,
596614 headers: headers,
597615 body: body,
598- timeout: timeout
616+ timeout: timeout,
617+ authorization: authorization
599618 )
600619 }
601620
@@ -607,14 +626,16 @@ class ApiRequestProvider: NSObject {
607626 /// - headers: HTTP headers
608627 /// - string: String to encode as UTF-8 body
609628 /// - timeout: Request timeout
629+ /// - authorization: If authorization header should be set
610630 /// - Returns: Configured API request
611631 func request(
612632 with method: ApiMethod ? = nil ,
613633 endpoint: ApiEndpoint ,
614634 queryItems: [ URLQueryItem ] = [ ] ,
615635 headers: ApiRequest . Headers = [ : ] ,
616636 string: String ,
617- timeout: TimeInterval = ApiDefaultTimeout
637+ timeout: TimeInterval = ApiDefaultTimeout,
638+ authorization: Bool = true
618639 ) -> ApiRequest {
619640 requestType. init (
620641 caller: caller,
@@ -623,7 +644,8 @@ class ApiRequestProvider: NSObject {
623644 queryItems: queryItems,
624645 headers: headers,
625646 body: string. data ( using: . utf8) ,
626- timeout: timeout
647+ timeout: timeout,
648+ authorization: authorization
627649 )
628650 }
629651
@@ -635,14 +657,16 @@ class ApiRequestProvider: NSObject {
635657 /// - headers: HTTP headers
636658 /// - form: Form data dictionary
637659 /// - timeout: Request timeout
660+ /// - authorization: If authorization header should be set
638661 /// - Returns: Configured API request
639662 func request(
640663 with method: ApiMethod ? = nil ,
641664 endpoint: ApiEndpoint ,
642665 queryItems: [ URLQueryItem ] = [ ] ,
643666 headers: ApiRequest . Headers = [ : ] ,
644667 form: ApiRequest . Form ,
645- timeout: TimeInterval = ApiDefaultTimeout
668+ timeout: TimeInterval = ApiDefaultTimeout,
669+ authorization: Bool = true
646670 ) -> ApiRequest {
647671 requestType. init (
648672 caller: caller,
@@ -651,7 +675,8 @@ class ApiRequestProvider: NSObject {
651675 queryItems: queryItems,
652676 headers: headers,
653677 form: form,
654- timeout: timeout
678+ timeout: timeout,
679+ authorization: authorization
655680 )
656681 }
657682
0 commit comments