Open onewilk opened 3 years ago
@onewilk thanks for reporting, we'll discuss this internally and see how much effort :)
a downside of it would be that this lib does not support Browser Apps, so we'd need to have a specific Client for Web
Because of the limitation on dart2js/flutter web, I'm not sure this is the way to go. We could add an abstraction to our use of http, and use our current implementation in the box, but allow users to swap it out as the OP requested.
You can set SentryOptions.client
to use a IOClient.
The IOClient constructor allows to use a dart:io HttpClient.
That should fix the original issue.
Remarks:
As the issue should be resolved now, I think this can be closed.
We should probably document this somewhere.
What do you think, @marandaneto ?
@ueman not really, the idea is that there's an easy way to set up a proxy via options and not replacing the whole transport layer.
the current http
lib does not allow that, but HttpClient
does, but it does not work for Web, so we'd need to think this thoroughly
You can't do a proxy setup in JS though. That's why it isn't available in the HTTP package by default. Using the IOClient from the HTTP package does what the original issue is about. You can do this already and it works for the Dart SDK, Windows and Linux. For platforms with a native integration, I would say this should be done with #265
Example :
import 'dart:io';
import 'package:http/io_client.dart';
import 'package:sentry/sentry.dart';
Sentry.init(
(options) {
final httpClient = HttpClient(); // from dart:io
httpClient.findProxy = (url) => "PROXY xxxx:xxxx";
final ioClient = IOClient(httpClient); // from package:http
options.client = ioClient;
}
)
@ueman if that works, sounds good, but instead of people doing such code snippet, we could do something like:
so they configure host, port, user, pass and we do the rest, this should be done then only by non-web env. and also, configure the native platforms for flutter (pass down the configuration when its available via message channel) as they are the ones sending the events.
if the issue is only about the proxy configuration, that's good.
the other question is, do we want to get rid of http
package and use only HttpClient
which is builtin on the Dart SDK?
the other question is, do we want to get rid of
http
package and use onlyHttpClient
which is builtin on the Dart SDK?
The built-in client is only available on dart:io. We would have to use XHR (ort he fetch api) on web. So basically we would need to write something like the HTTP package ourself. I would say it's not worth it.
sounds good, lets just make it easier to set up the proxy then (internally using the IOClient
) as suggested, but let's keep the Client
lib, this is not a breaking change anymore then but rather a feat, will remove the 6.0.0 milestone.
In some case, developers need to config httpClient proxy settings to request the public network cause company's network security requirement.
So here is the problem:
Client is an abstract class from the http lib, and it doesn't offer the proxy setup yet.
Please migrate Client to HttpClient from dart:io.
then developers could set proxy just like this
or just use project's global singleton HttpClient object directly.
Sorry for my poor english ~