Expose HttpClient in APIs

This commit is contained in:
Mattia 2020-09-03 20:49:22 +02:00
parent ecfd75617c
commit fd88cf0907
2 changed files with 8 additions and 3 deletions

View File

@ -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<String, String> _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;

View File

@ -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);