-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
699 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:meta/meta.dart'; | ||
import 'package:http/http.dart'; | ||
|
||
import '../sentry_options.dart'; | ||
|
||
@internal | ||
ClientProvider getClientProvider() { | ||
return ClientProvider(); | ||
} | ||
|
||
@internal | ||
class ClientProvider { | ||
Client getClient(SentryOptions options) { | ||
return Client(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:http/http.dart'; | ||
import 'package:http/io_client.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
import '../protocol.dart'; | ||
import '../protocol/sentry_proxy.dart'; | ||
import '../sentry_options.dart'; | ||
import 'client_provider.dart'; | ||
|
||
@internal | ||
ClientProvider getClientProvider() { | ||
return IoClientProvider( | ||
() { | ||
return HttpClient(); | ||
}, | ||
(user, pass) { | ||
return HttpClientBasicCredentials(user, pass); | ||
}, | ||
); | ||
} | ||
|
||
@internal | ||
class IoClientProvider implements ClientProvider { | ||
final HttpClient Function() _httpClient; | ||
final HttpClientCredentials Function(String, String) _httpClientCredentials; | ||
|
||
IoClientProvider(this._httpClient, this._httpClientCredentials); | ||
|
||
@override | ||
Client getClient(SentryOptions options) { | ||
final proxy = options.proxy; | ||
if (proxy == null) { | ||
return Client(); | ||
} | ||
final pac = proxy.toPacString(); | ||
if (proxy.type == SentryProxyType.socks) { | ||
options.logger( | ||
SentryLevel.warning, | ||
"Setting proxy '$pac' is not supported.", | ||
); | ||
return Client(); | ||
} | ||
options.logger( | ||
SentryLevel.info, | ||
"Setting proxy '$pac'", | ||
); | ||
final httpClient = _httpClient(); | ||
httpClient.findProxy = (url) => pac; | ||
|
||
final host = proxy.host; | ||
final port = proxy.port; | ||
final user = proxy.user; | ||
final pass = proxy.pass; | ||
|
||
if (host != null && port != null && user != null && pass != null) { | ||
httpClient.addProxyCredentials( | ||
host, | ||
port, | ||
'', | ||
_httpClientCredentials(user, pass), | ||
); | ||
} | ||
return IOClient(httpClient); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class SentryProxy { | ||
final SentryProxyType type; | ||
final String? host; | ||
final int? port; | ||
final String? user; | ||
final String? pass; | ||
|
||
SentryProxy({required this.type, this.host, this.port, this.user, this.pass}); | ||
|
||
String toPacString() { | ||
String type = 'DIRECT'; | ||
switch (this.type) { | ||
case SentryProxyType.direct: | ||
return 'DIRECT'; | ||
case SentryProxyType.http: | ||
type = 'PROXY'; | ||
break; | ||
case SentryProxyType.socks: | ||
type = 'SOCKS'; | ||
break; | ||
} | ||
if (host != null && port != null) { | ||
return '$type $host:$port'; | ||
} else if (host != null) { | ||
return '$type $host'; | ||
} else { | ||
return 'DIRECT'; | ||
} | ||
} | ||
|
||
/// Produces a [Map] that can be serialized to JSON. | ||
Map<String, dynamic> toJson() { | ||
return { | ||
if (host != null) 'host': host, | ||
if (port != null) 'port': port, | ||
'type': type.toString().split('.').last.toUpperCase(), | ||
if (user != null) 'user': user, | ||
if (pass != null) 'pass': pass, | ||
}; | ||
} | ||
|
||
SentryProxy copyWith({ | ||
String? host, | ||
int? port, | ||
SentryProxyType? type, | ||
String? user, | ||
String? pass, | ||
}) => | ||
SentryProxy( | ||
host: host ?? this.host, | ||
port: port ?? this.port, | ||
type: type ?? this.type, | ||
user: user ?? this.user, | ||
pass: pass ?? this.pass, | ||
); | ||
} | ||
|
||
enum SentryProxyType { | ||
direct, | ||
http, | ||
socks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.