Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Ref: execute before send callback
- Feat: add lastEventId to the Sentry static API
- Feat: addBreadcrumb on Static API
- Fix: NoOp encode for Web

# `package:sentry` changelog

Expand Down
17 changes: 0 additions & 17 deletions dart/lib/src/transport/body_encoder.dart

This file was deleted.

12 changes: 0 additions & 12 deletions dart/lib/src/transport/body_encoder_browser.dart

This file was deleted.

7 changes: 7 additions & 0 deletions dart/lib/src/transport/encode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'dart:io';

/// Encodes the body using Gzip compression
List<int> compressBody(List<int> body, Map<String, String> headers) {
headers['Content-Encoding'] = 'gzip';
return gzip.encode(body);
}
2 changes: 2 additions & 0 deletions dart/lib/src/transport/noop_encode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// gzip compression is not available on browser
List<int> compressBody(List<int> body, Map<String, String> headers) => body;
24 changes: 16 additions & 8 deletions dart/lib/src/transport/transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import 'package:sentry/src/utils.dart';

import '../protocol.dart';
import '../sentry_options.dart';
import 'body_encoder_browser.dart' if (dart.library.io) 'body_encoder.dart';

typedef BodyEncoder = List<int> Function(
Map<String, dynamic> data,
Map<String, String> headers, {
bool compressPayload,
});
import 'noop_encode.dart' if (dart.library.io) 'encode.dart';

/// A transport is in charge of sending the event to the Sentry server.
class Transport {
Expand Down Expand Up @@ -43,7 +37,7 @@ class Transport {
Future<SentryId> send(SentryEvent event) async {
final data = event.toJson(origin: _origin);

final body = bodyEncoder(
final body = _bodyEncoder(
data,
_headers,
compressPayload: _options.compressPayload,
Expand All @@ -62,6 +56,20 @@ class Transport {
final eventId = json.decode(response.body)['id'];
return eventId != null ? SentryId.fromId(eventId) : SentryId.empty();
}

List<int> _bodyEncoder(
Map<String, dynamic> data,
Map<String, String> headers, {
bool compressPayload,
}) {
// [SentryIOClient] implement gzip compression
// gzip compression is not available on browser
var body = utf8.encode(json.encode(data));
if (compressPayload) {
body = compressBody(body, headers);
}
return body;
}
}

class CredentialBuilder {
Expand Down