mirror of
https://github.com/foss42/apidash.git
synced 2025-12-11 07:41:14 +08:00
feat: enhance oauth flow with json accept header support
This commit is contained in:
@@ -10,6 +10,23 @@ http.Client createHttpClientWithNoSSL() {
|
||||
return IOClient(ioClient);
|
||||
}
|
||||
|
||||
class _JsonAcceptClient extends http.BaseClient {
|
||||
final http.Client _inner;
|
||||
|
||||
_JsonAcceptClient(this._inner);
|
||||
|
||||
@override
|
||||
Future<http.StreamedResponse> send(http.BaseRequest request) {
|
||||
request.headers['Accept'] = 'application/json';
|
||||
return _inner.send(request);
|
||||
}
|
||||
|
||||
@override
|
||||
void close() {
|
||||
_inner.close();
|
||||
}
|
||||
}
|
||||
|
||||
class HttpClientManager {
|
||||
static final HttpClientManager _instance = HttpClientManager._internal();
|
||||
static const int _maxCancelledRequests = 100;
|
||||
@@ -60,4 +77,17 @@ class HttpClientManager {
|
||||
bool hasActiveClient(String requestId) {
|
||||
return _clients.containsKey(requestId);
|
||||
}
|
||||
|
||||
http.Client createClientWithJsonAccept(
|
||||
String requestId, {
|
||||
bool noSSL = false,
|
||||
}) {
|
||||
final baseClient = (noSSL && !kIsWeb)
|
||||
? createHttpClientWithNoSSL()
|
||||
: http.Client();
|
||||
|
||||
final client = _JsonAcceptClient(baseClient);
|
||||
_clients[requestId] = client;
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user