diff --git a/lib/src/reverse_engineering/youtube_http_client.dart b/lib/src/reverse_engineering/youtube_http_client.dart index 3bc1711..4dadd2f 100644 --- a/lib/src/reverse_engineering/youtube_http_client.dart +++ b/lib/src/reverse_engineering/youtube_http_client.dart @@ -5,9 +5,9 @@ import 'package:http/http.dart' as http; import '../exceptions/exceptions.dart'; import '../videos/streams/streams.dart'; -/// +/// HttpClient wrapper for YouTube class YoutubeHttpClient extends http.BaseClient { - final http.Client _httpClient = http.Client(); + final http.Client _httpClient; final Map _defaultHeaders = const { 'user-agent': @@ -23,6 +23,10 @@ class YoutubeHttpClient extends http.BaseClient { 'x-youtube-page-label': 'youtube.ytfe.desktop_20200617_1_RC1' }; + /// Initialize an instance of [YoutubeHttpClient] + YoutubeHttpClient([http.Client httpClient]) + : _httpClient = httpClient ?? http.Client(); + /// Throws if something is wrong with the response. void _validateResponse(http.BaseResponse response, int statusCode) { var request = response.request; diff --git a/lib/src/youtube_explode_base.dart b/lib/src/youtube_explode_base.dart index d711671..bd83af5 100644 --- a/lib/src/youtube_explode_base.dart +++ b/lib/src/youtube_explode_base.dart @@ -23,7 +23,8 @@ class YoutubeExplode { SearchClient get search => _search; /// Initializes an instance of [YoutubeClient]. - YoutubeExplode() : _httpClient = YoutubeHttpClient() { + YoutubeExplode([YoutubeHttpClient httpClient]) + : _httpClient = httpClient ?? YoutubeHttpClient() { _videos = VideoClient(_httpClient); _playlists = PlaylistClient(_httpClient); _channels = ChannelClient(_httpClient);