mirror of
https://github.com/foss42/apidash.git
synced 2025-12-03 03:17:00 +08:00
Refactor auth handling in HTTP request functions
Removed redundant AuthModel parameter from sendHttpRequest and streamHttpRequest functions, now using authModel from HttpRequestModel directly. Updated all usages, tests, and related logic to reflect this change. Improved streaming response handling in CollectionStateNotifier and HttpResponseModel.
This commit is contained in:
@@ -62,7 +62,11 @@ class HttpResponseModel with _$HttpResponseModel {
|
||||
String? get contentType => headers?.getValueContentType();
|
||||
MediaType? get mediaType => getMediaTypeFromHeaders(headers);
|
||||
|
||||
HttpResponseModel fromResponse({required Response response, Duration? time}) {
|
||||
HttpResponseModel fromResponse({
|
||||
required Response response,
|
||||
Duration? time,
|
||||
bool isStreamingResponse = false,
|
||||
}) {
|
||||
final responseHeaders = mergeMaps({
|
||||
HttpHeaders.contentLengthHeader: response.contentLength.toString(),
|
||||
}, response.headers);
|
||||
@@ -80,6 +84,7 @@ class HttpResponseModel with _$HttpResponseModel {
|
||||
formattedBody: formatBody(body, mediaType),
|
||||
bodyBytes: response.bodyBytes,
|
||||
time: time,
|
||||
sseOutput: isStreamingResponse ? [body] : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,6 @@ Future<(HttpResponse?, Duration?, String?)> sendHttpRequestV1(
|
||||
Future<(HttpResponse?, Duration?, String?)> sendHttpRequest(
|
||||
String requestId,
|
||||
APIType apiType,
|
||||
AuthModel? authData,
|
||||
HttpRequestModel requestModel, {
|
||||
SupportedUriSchemes defaultUriScheme = kDefaultUriScheme,
|
||||
bool noSSL = false,
|
||||
@@ -166,7 +165,6 @@ Future<(HttpResponse?, Duration?, String?)> sendHttpRequest(
|
||||
final stream = await streamHttpRequest(
|
||||
requestId,
|
||||
apiType,
|
||||
authData,
|
||||
requestModel,
|
||||
defaultUriScheme: defaultUriScheme,
|
||||
noSSL: noSSL,
|
||||
@@ -206,11 +204,11 @@ http.Request prepareHttpRequest({
|
||||
Future<Stream<HttpStreamOutput>> streamHttpRequest(
|
||||
String requestId,
|
||||
APIType apiType,
|
||||
AuthModel? authData,
|
||||
HttpRequestModel httpRequestModel, {
|
||||
SupportedUriSchemes defaultUriScheme = kDefaultUriScheme,
|
||||
bool noSSL = false,
|
||||
}) async {
|
||||
final authData = httpRequestModel.authModel;
|
||||
final controller = StreamController<HttpStreamOutput>();
|
||||
StreamSubscription<List<int>?>? subscription;
|
||||
final stopwatch = Stopwatch()..start();
|
||||
|
||||
@@ -109,7 +109,6 @@ Future<HttpRequestModel> handleAuth(
|
||||
final httpResult = await sendHttpRequest(
|
||||
"digest-${Random.secure()}",
|
||||
APIType.rest,
|
||||
null,
|
||||
httpRequestModel,
|
||||
);
|
||||
final httpResponse = httpResult.$1;
|
||||
|
||||
Reference in New Issue
Block a user