Skip to content

Commit 3224a90

Browse files
committed
Convert url request to Swift
1 parent 95cfd20 commit 3224a90

19 files changed

+160
-317
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Crashes for uncaught NSExceptions will now report the stracktrace recorded within the exception (#5306)
1919
- Move SentryExperimentalOptions to a property defined in Swift (#5329)
2020
- Add redaction in session replay for `SFSafariView` used by `SFSafariViewController` and `ASWebAuthenticationSession` (#5408)
21+
- Convert SentryNSURLRequest to Swift (#5451)
2122

2223
### Fixes
2324

Sentry.xcodeproj/project.pbxproj

Lines changed: 12 additions & 16 deletions
Large diffs are not rendered by default.

Sources/Sentry/SentryHttpTransport.m

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#import "SentryEvent.h"
1616
#import "SentryFileManager.h"
1717
#import "SentryLog.h"
18-
#import "SentryNSURLRequest.h"
19-
#import "SentryNSURLRequestBuilder.h"
2018
#import "SentryOptions.h"
2119
#import "SentrySerialization.h"
2220
#import "SentrySwift.h"
@@ -339,14 +337,13 @@ - (void)sendAllCachedEnvelopes
339337
rateLimitedEnvelope.header.sentAt = SentryDependencyContainer.sharedInstance.dateProvider.date;
340338

341339
NSError *requestError = nil;
342-
NSURLRequest *request = [self.requestBuilder createEnvelopeRequest:rateLimitedEnvelope
343-
dsn:self.options.parsedDsn
344-
didFailWithError:&requestError];
340+
NSURLRequest *request =
341+
[self.requestBuilder createEnvelopeRequestWithEnvelope:rateLimitedEnvelope
342+
dsn:self.options.parsedDsn
343+
error:&requestError];
345344

346-
if (nil == request || nil != requestError) {
347-
if (nil != requestError) {
348-
SENTRY_LOG_DEBUG(@"Failed to build request: %@.", requestError);
349-
}
345+
if (nil != requestError) {
346+
SENTRY_LOG_DEBUG(@"Failed to build request: %@.", requestError);
350347
[self recordLostEventFor:rateLimitedEnvelope.items];
351348
[self deleteEnvelopeAndSendNext:envelopeFilePath];
352349
return;

Sources/Sentry/SentryNSURLRequest.m

Lines changed: 0 additions & 85 deletions
This file was deleted.

Sources/Sentry/SentryNSURLRequestBuilder.m

Lines changed: 0 additions & 42 deletions
This file was deleted.

Sources/Sentry/SentrySpotlightTransport.m

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#import "SentryEnvelopeItemHeader.h"
55
#import "SentryEnvelopeItemType.h"
66
#import "SentryLog.h"
7-
#import "SentryNSURLRequest.h"
8-
#import "SentryNSURLRequestBuilder.h"
97
#import "SentryOptions.h"
108
#import "SentrySerialization.h"
9+
#import "SentrySwift.h"
1110
#import "SentryTransport.h"
1211

1312
NS_ASSUME_NONNULL_BEGIN
@@ -66,14 +65,12 @@ - (void)sendEnvelope:(SentryEnvelope *)envelope
6665
items:allowedEnvelopeItems];
6766

6867
NSError *requestError = nil;
69-
NSURLRequest *request = [self.requestBuilder createEnvelopeRequest:envelopeToSend
70-
url:self.apiURL
71-
didFailWithError:&requestError];
68+
NSURLRequest *request = [self.requestBuilder createEnvelopeRequestWithEnvelope:envelopeToSend
69+
url:self.apiURL
70+
error:&requestError];
7271

73-
if (nil == request || nil != requestError) {
74-
if (nil != requestError) {
75-
SENTRY_LOG_ERROR(@"Unable to build envelope request with error %@", requestError);
76-
}
72+
if (nil != requestError) {
73+
SENTRY_LOG_ERROR(@"Unable to build envelope request with error %@", requestError);
7774
return;
7875
}
7976

Sources/Sentry/SentryTransportFactory.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#import "SentryEnvelopeRateLimit.h"
55
#import "SentryHttpDateParser.h"
66
#import "SentryHttpTransport.h"
7-
#import "SentryNSURLRequestBuilder.h"
87
#import "SentryOptions.h"
98
#import "SentryQueueableRequestManager.h"
109
#import "SentryRateLimitParser.h"
1110
#import "SentryRateLimits.h"
1211

1312
#import "SentryRetryAfterHeaderParser.h"
1413
#import "SentrySpotlightTransport.h"
14+
#import "SentrySwift.h"
1515
#import "SentryTransport.h"
1616

1717
NS_ASSUME_NONNULL_BEGIN

Sources/Sentry/include/SentryNSURLRequest.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/Sentry/include/SentryNSURLRequestBuilder.h

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@_implementationOnly import _SentryPrivate
2+
3+
private enum Error: Swift.Error {
4+
case serializationError
5+
}
6+
7+
@objc(SentryNSURLRequestBuilder)
8+
@_spi(Private) public class SentryURLRequestBuilder: NSObject {
9+
10+
@objc
11+
public func createEnvelopeRequest(envelope: SentryEnvelope, dsn: SentryDsn) throws -> URLRequest {
12+
guard let data = SentrySerialization.data(with: envelope) else {
13+
SentryLog.error("Envelope cannot be converted to data")
14+
throw Error.serializationError
15+
}
16+
return try SentryURLRequestFactory.envelopeRequest(with: dsn, data: data)
17+
}
18+
19+
@objc
20+
public func createEnvelopeRequest(envelope: SentryEnvelope, url: URL) throws -> URLRequest {
21+
guard let data = SentrySerialization.data(with: envelope) else {
22+
SentryLog.error("Envelope cannot be converted to data")
23+
throw Error.serializationError
24+
}
25+
return try SentryURLRequestFactory.envelopeRequest(with: url, data: data, authHeader: nil)
26+
}
27+
}

0 commit comments

Comments
 (0)