From 3fdb74932e92706074ba0a0bf66260f314136d6f Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Fri, 25 Nov 2022 06:26:49 -0300 Subject: [PATCH] ref: Remove default attachment content type (#2443) Removed the default attachment content type. This is defined at server side. --- CHANGELOG.md | 1 + Sources/Sentry/Public/SentryAttachment.h | 12 ++++++------ Sources/Sentry/SentryAttachment.m | 10 ++++------ Sources/Sentry/SentrySerialization.m | 2 +- .../SentryTests/Protocol/SentryAttachmentTests.swift | 8 ++++---- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6709d212f53..33ac0acc0dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ This version adds a dependency on Swift. - Remove `- [SentryOptions sdkInfo]` (#2404) - Marks App hang's event stacktrace snapshot as true (#2441) - Enable user interaction tracing by default (#2442) +- Remove default attachment content type (#2443) ## 7.31.2 diff --git a/Sources/Sentry/Public/SentryAttachment.h b/Sources/Sentry/Public/SentryAttachment.h index 6a834143d21..b9217094dc1 100644 --- a/Sources/Sentry/Public/SentryAttachment.h +++ b/Sources/Sentry/Public/SentryAttachment.h @@ -27,7 +27,7 @@ SENTRY_NO_INIT */ - (instancetype)initWithData:(NSData *)data filename:(NSString *)filename - contentType:(NSString *)contentType; + contentType:(nullable NSString *)contentType; /** * Initializes an attachment with a path. Uses the last path compontent of the path as a filename @@ -63,17 +63,17 @@ SENTRY_NO_INIT */ - (instancetype)initWithPath:(NSString *)path filename:(NSString *)filename - contentType:(NSString *)contentType; + contentType:(nullable NSString *)contentType; /** * The data of the attachment. */ -@property (readonly, nonatomic, strong) NSData *_Nullable data; +@property (readonly, nonatomic, strong, nullable) NSData *data; /** * The path of the attachment. */ -@property (readonly, nonatomic, copy) NSString *_Nullable path; +@property (readonly, nonatomic, copy, nullable) NSString *path; /** * The filename of the attachment to display in Sentry. @@ -81,9 +81,9 @@ SENTRY_NO_INIT @property (readonly, nonatomic, copy) NSString *filename; /** - * The content type of the attachment. Default is "application/octet-stream". + * The content type of the attachment. */ -@property (readonly, nonatomic, copy) NSString *contentType; +@property (readonly, nonatomic, copy, nullable) NSString *contentType; @end diff --git a/Sources/Sentry/SentryAttachment.m b/Sources/Sentry/SentryAttachment.m index 7c92dd7f78d..3e4a96f9c09 100644 --- a/Sources/Sentry/SentryAttachment.m +++ b/Sources/Sentry/SentryAttachment.m @@ -3,18 +3,16 @@ NS_ASSUME_NONNULL_BEGIN -NSString *const DefaultContentType = @"application/octet-stream"; - @implementation SentryAttachment - (instancetype)initWithData:(NSData *)data filename:(NSString *)filename { - return [self initWithData:data filename:filename contentType:DefaultContentType]; + return [self initWithData:data filename:filename contentType:nil]; } - (instancetype)initWithData:(NSData *)data filename:(NSString *)filename - contentType:(NSString *)contentType + contentType:(nullable NSString *)contentType { if (self = [super init]) { @@ -32,12 +30,12 @@ - (instancetype)initWithPath:(NSString *)path - (instancetype)initWithPath:(NSString *)path filename:(NSString *)filename { - return [self initWithPath:path filename:filename contentType:DefaultContentType]; + return [self initWithPath:path filename:filename contentType:nil]; } - (instancetype)initWithPath:(NSString *)path filename:(NSString *)filename - contentType:(NSString *)contentType + contentType:(nullable NSString *)contentType { if (self = [super init]) { _path = path; diff --git a/Sources/Sentry/SentrySerialization.m b/Sources/Sentry/SentrySerialization.m index b20f31431c0..2404f76696f 100644 --- a/Sources/Sentry/SentrySerialization.m +++ b/Sources/Sentry/SentrySerialization.m @@ -284,7 +284,7 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data NSString *_Nullable contentType = [headerDictionary valueForKey:@"content_type"]; SentryEnvelopeItemHeader *itemHeader; - if (nil != filename && nil != contentType) { + if (nil != filename) { itemHeader = [[SentryEnvelopeItemHeader alloc] initWithType:type length:bodyLength filenname:filename diff --git a/Tests/SentryTests/Protocol/SentryAttachmentTests.swift b/Tests/SentryTests/Protocol/SentryAttachmentTests.swift index fbd783f43b3..9179805adb9 100644 --- a/Tests/SentryTests/Protocol/SentryAttachmentTests.swift +++ b/Tests/SentryTests/Protocol/SentryAttachmentTests.swift @@ -27,7 +27,7 @@ class SentryAttachmentTests: XCTestCase { XCTAssertEqual(fixture.data, attachment.data) XCTAssertEqual(fixture.filename, attachment.filename) - XCTAssertEqual(fixture.defaultContentType, attachment.contentType) + XCTAssertNil(attachment.contentType) XCTAssertNil(attachment.path) } @@ -45,7 +45,7 @@ class SentryAttachmentTests: XCTestCase { XCTAssertEqual(fixture.path, attachment.path) XCTAssertEqual(fixture.filename, attachment.filename) - XCTAssertEqual(fixture.defaultContentType, attachment.contentType) + XCTAssertNil(attachment.contentType) XCTAssertNil(attachment.data) } @@ -54,7 +54,7 @@ class SentryAttachmentTests: XCTestCase { XCTAssertEqual("", attachment.path) XCTAssertEqual("", attachment.filename) - XCTAssertEqual(fixture.defaultContentType, attachment.contentType) + XCTAssertNil(attachment.contentType) XCTAssertNil(attachment.data) } @@ -87,7 +87,7 @@ class SentryAttachmentTests: XCTestCase { XCTAssertEqual(fixture.path, attachment.path) XCTAssertEqual(filename, attachment.filename) - XCTAssertEqual(fixture.defaultContentType, attachment.contentType) + XCTAssertNil(attachment.contentType) XCTAssertNil(attachment.data) }