Closed abdelaziz-mahdy closed 1 year ago
Hi, thanks for the PR, although this is already how the code works, ie. when calling super.get
, super.post
, internally the this.send
method is called so each request uses the passed http client. If you want to use a custom url to bypass the CORS, here is an example if you are using https://github.com/Rob--W/cors-anywhere .
class CorsBypassClient extends http.BaseClient {
final _client = http.Client();
@override
Future<http.StreamedResponse> send(covariant http.Request request) {
final uri = request.url;
final http.BaseRequest newRequest = http.Request(
request.method,
request.url.replace(
host: 'cors-anywhere.myinstance.com',
pathSegments: [uri.host, ...uri.pathSegments]))
..headers.addAll({
...request.headers,
'origin': 'https://www.youtube.com',
'x-requested-with': 'https://www.youtube.com',
})
..bodyBytes = request.bodyBytes;
return _client.send(newRequest);
}
}
...
final yt = YoutubeExplode(YoutubeHttpClient(CorsBypassClient()));
Note that it might still need some tweaking, and if a lot of users are using the same CORS server it might be rate limited.
Thank you very much, for the explanation.
Will check the code you mentioned.
this may help with the web problem my idea is pass an http client in which
web: all urls gets send with a cors middleware other: send same url
I am avoiding breaking changes by making people implement their own http clients if you dont mind a breaking change in YoutubeHttpClient let me know
most probably it will be like this