diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f27feb897..76e252b370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Feat: Relax TransactionNameProvider (#1861) * Ref: Simplify DateUtils with ISO8601Utils (#1837) +* Ref: Remove Attachment ContentType since the Server infers it (#1874) * Ref: Add shutdownTimeoutMillis in favor of shutdownTimeout (#1873) ## 6.0.0-alpha.1 diff --git a/sentry/src/main/java/io/sentry/Attachment.java b/sentry/src/main/java/io/sentry/Attachment.java index 2d644ca31b..a519f64b60 100644 --- a/sentry/src/main/java/io/sentry/Attachment.java +++ b/sentry/src/main/java/io/sentry/Attachment.java @@ -10,21 +10,12 @@ public final class Attachment { private @Nullable byte[] bytes; private @Nullable String pathname; private final @NotNull String filename; - private final @NotNull String contentType; + private final @Nullable String contentType; private final boolean addToTransactions; /** The special type of this attachment */ private @Nullable String attachmentType = DEFAULT_ATTACHMENT_TYPE; - /** - * We could use Files.probeContentType(path) to determine the content type of the filename. This - * needs a path, but file.toPath or Paths.get only work on above Android API level 26, see - * https://developer.android.com/reference/java/nio/file/Paths. There are also ways via - * URLConnection, but we don't want to use this in constructors. Therefore we use the default - * content type of Sentry. - */ - private static final String DEFAULT_CONTENT_TYPE = "application/octet-stream"; - /** A standard attachment without special meaning */ private static final String DEFAULT_ATTACHMENT_TYPE = "event.attachment"; @@ -36,7 +27,7 @@ public final class Attachment { * @param filename The name of the attachment to display in Sentry. */ public Attachment(final @NotNull byte[] bytes, final @NotNull String filename) { - this(bytes, filename, DEFAULT_CONTENT_TYPE); + this(bytes, filename, null); } /** @@ -50,7 +41,7 @@ public Attachment(final @NotNull byte[] bytes, final @NotNull String filename) { public Attachment( final @NotNull byte[] bytes, final @NotNull String filename, - final @NotNull String contentType) { + final @Nullable String contentType) { this(bytes, filename, contentType, false); } @@ -66,7 +57,7 @@ public Attachment( public Attachment( final @NotNull byte[] bytes, final @NotNull String filename, - final @NotNull String contentType, + final @Nullable String contentType, final boolean addToTransactions) { this.bytes = bytes; this.filename = filename; @@ -100,7 +91,7 @@ public Attachment(final @NotNull String pathname) { * @param filename The name of the attachment to display in Sentry. */ public Attachment(final @NotNull String pathname, final @NotNull String filename) { - this(pathname, filename, DEFAULT_CONTENT_TYPE); + this(pathname, filename, null); } /** @@ -118,7 +109,7 @@ public Attachment(final @NotNull String pathname, final @NotNull String filename public Attachment( final @NotNull String pathname, final @NotNull String filename, - final @NotNull String contentType) { + final @Nullable String contentType) { this(pathname, filename, contentType, false); } @@ -138,7 +129,7 @@ public Attachment( public Attachment( final @NotNull String pathname, final @NotNull String filename, - final @NotNull String contentType, + final @Nullable String contentType, final boolean addToTransactions) { this.pathname = pathname; this.filename = filename; @@ -164,7 +155,7 @@ public Attachment( public Attachment( final @NotNull String pathname, final @NotNull String filename, - final @NotNull String contentType, + final @Nullable String contentType, final boolean addToTransactions, final @Nullable String attachmentType) { this.pathname = pathname; @@ -202,11 +193,12 @@ public Attachment( } /** - * Gets the content type of the attachment. Default is "application/octet-stream". + * Gets the content type of the attachment. The server infers "application/octet-stream" if not + * set. * - * @return the content type. + * @return the content type or null if not set. */ - public @NotNull String getContentType() { + public @Nullable String getContentType() { return contentType; } diff --git a/sentry/src/test/java/io/sentry/AttachmentTest.kt b/sentry/src/test/java/io/sentry/AttachmentTest.kt index b81c4562d7..a6b966ac00 100644 --- a/sentry/src/test/java/io/sentry/AttachmentTest.kt +++ b/sentry/src/test/java/io/sentry/AttachmentTest.kt @@ -9,7 +9,6 @@ import kotlin.test.assertTrue class AttachmentTest { private class Fixture { - val defaultContentType = "application/octet-stream" val contentType = "application/json" val filename = "logs.txt" val bytes = "content".toByteArray() @@ -25,7 +24,6 @@ class AttachmentTest { assertEquals(fixture.bytes, attachment.bytes) assertNull(attachment.pathname) assertEquals(fixture.filename, attachment.filename) - assertEquals(fixture.defaultContentType, attachment.contentType) } @Test @@ -35,7 +33,6 @@ class AttachmentTest { assertEquals(fixture.pathname, attachment.pathname) assertNull(attachment.bytes) assertEquals(fixture.filename, attachment.filename) - assertEquals(fixture.defaultContentType, attachment.contentType) } @Test @@ -62,7 +59,6 @@ class AttachmentTest { assertEquals(fixture.pathname, attachment.pathname) assertNull(attachment.bytes) assertEquals(otherFileName, attachment.filename) - assertEquals(fixture.defaultContentType, attachment.contentType) } @Test diff --git a/sentry/src/test/java/io/sentry/JsonSerializerTest.kt b/sentry/src/test/java/io/sentry/JsonSerializerTest.kt index ed1d8a0c1d..84d5c096e7 100644 --- a/sentry/src/test/java/io/sentry/JsonSerializerTest.kt +++ b/sentry/src/test/java/io/sentry/JsonSerializerTest.kt @@ -703,8 +703,7 @@ class JsonSerializerTest { val actualJson = serializeToString(envelope) val expectedJson = "{\"event_id\":\"${eventID}\"}\n" + - "{\"content_type\":\"${attachment.contentType}\"," + - "\"filename\":\"${attachment.filename}\"," + + "{\"filename\":\"${attachment.filename}\"," + "\"type\":\"attachment\"," + "\"attachment_type\":\"event.attachment\"," + "\"length\":${attachment.bytes?.size}}\n" +