-
-
Notifications
You must be signed in to change notification settings - Fork 277
Refacto : add a Transport class #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a10d740
623c904
0dcb613
c97c98b
477fdac
b8fb322
fd92e3f
0944c68
46829fc
01d4e19
fbd001e
4d39531
34fb528
2437fa4
57798f5
789e154
1aa05d6
9895142
cb5e309
e563d2c
71b53c8
be3f0a2
43b798c
19dc91d
cec1f21
909d4f9
8b600dc
4ff58a6
5493e19
621d6c4
e11f653
88526e2
796b633
fb8b9e0
1dbcba4
8b56bce
daeb29e
098d58c
2833a94
35671d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,6 @@ class SentryBrowserClient extends SentryClient { | |
| clock: options.clock, | ||
| compressPayload: false, | ||
| sdk: Sdk(name: browserSdkName, version: sdkVersion), | ||
|
||
| headersBuilder: SentryClient.buildHeaders, | ||
| platform: platform, | ||
|
||
| origin: origin, | ||
| ), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import '../protocol.dart'; | ||
|
|
||
| Map<String, String> buildHeaders(String authHeader, {Sdk sdk}) { | ||
| final headers = { | ||
| 'Content-Type': 'application/json', | ||
| }; | ||
|
|
||
| if (authHeader != null) { | ||
| headers['X-Sentry-Auth'] = authHeader; | ||
| } | ||
|
|
||
| // NOTE(lejard_h) overriding user agent on VM and Flutter not sure why | ||
| // for web it use browser user agent | ||
| headers['User-Agent'] = sdk.identifier; | ||
|
||
|
|
||
| return headers; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import '../protocol.dart'; | ||
|
|
||
| Map<String, String> buildHeaders(String authHeader, {Sdk sdk}) { | ||
| final headers = { | ||
| 'Content-Type': 'application/json', | ||
| }; | ||
|
|
||
| if (authHeader != null) { | ||
| headers['X-Sentry-Auth'] = authHeader; | ||
| } | ||
|
|
||
| return headers; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,14 @@ 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'; | ||
| import 'header_builder_browser.dart' if (dart.library.io) 'header_builder.dart'; | ||
|
|
||
| typedef BodyEncoder = List<int> Function( | ||
| Map<String, dynamic> data, | ||
| Map<String, String> headers, { | ||
| bool compressPayload, | ||
| }); | ||
|
|
||
| typedef HeadersBuilder = Map<String, String> Function(String authHeader); | ||
|
|
||
| /// A transport is in charge of sending the event to the Sentry server. | ||
| class Transport { | ||
| final Client httpClient; | ||
|
|
@@ -25,8 +24,6 @@ class Transport { | |
|
|
||
| final Sdk sdk; | ||
|
|
||
| final HeadersBuilder headersBuilder; | ||
|
|
||
| final bool compressPayload; | ||
|
|
||
| /// Used by sentry to differentiate browser from io environment | ||
|
|
@@ -43,7 +40,6 @@ class Transport { | |
| @required this.httpClient, | ||
| @required this.sdk, | ||
| @required ClockProvider clock, | ||
| @required this.headersBuilder, | ||
| @required this.platform, | ||
| this.origin, | ||
| }) : _dsn = Dsn.parse(dsn), | ||
|
|
@@ -77,7 +73,9 @@ class Transport { | |
| (dsnUri.scheme == 'https' && dsnUri.port != 443)) | ||
| ? ':${dsnUri.port}' | ||
| : ''; | ||
|
|
||
| final pathLength = dsnUri.pathSegments.length; | ||
|
|
||
| String apiPath; | ||
| if (pathLength > 1) { | ||
| // some paths would present before the projectID in the dsnUri | ||
|
|
@@ -91,6 +89,7 @@ class Transport { | |
|
|
||
| Future<SentryId> send(Map<String, dynamic> data) async { | ||
|
||
| final now = _clock(); | ||
|
|
||
| var authHeader = 'Sentry sentry_version=6, sentry_client=$clientId, ' | ||
|
||
| 'sentry_timestamp=${now.millisecondsSinceEpoch}, sentry_key=$publicKey'; | ||
| if (secretKey != null) { | ||
|
|
@@ -99,7 +98,7 @@ class Transport { | |
|
|
||
| mergeAttributes(_getContext(now), into: data); | ||
|
|
||
| final headers = headersBuilder(authHeader); | ||
| final headers = buildHeaders(authHeader, sdk: sdk); | ||
|
|
||
| final body = bodyEncoder(data, headers, compressPayload: compressPayload); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.