Skip to content

Commit b186b29

Browse files
committed
style: dart formatting
1 parent 9c0fb47 commit b186b29

File tree

4 files changed

+56
-34
lines changed

4 files changed

+56
-34
lines changed

lib/http/intercepted_client.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,13 @@ class InterceptedClient extends BaseClient {
292292
} else {
293293
// Use a completer to properly handle timeout and cancellation
294294
final completer = Completer<StreamedResponse>();
295-
final Future<StreamedResponse> requestFuture = _inner.send(interceptedRequest);
296-
295+
final Future<StreamedResponse> requestFuture =
296+
_inner.send(interceptedRequest);
297+
297298
// Set up timeout with proper cleanup
298299
Timer? timeoutTimer;
299300
late StreamSubscription streamSubscription;
300-
301+
301302
timeoutTimer = Timer(requestTimeout!, () {
302303
if (!completer.isCompleted) {
303304
if (onRequestTimeout != null) {
@@ -318,13 +319,12 @@ class InterceptedClient extends BaseClient {
318319
// Default timeout behavior
319320
if (!completer.isCompleted) {
320321
completer.completeError(Exception(
321-
'Request timeout after ${requestTimeout!.inMilliseconds}ms'
322-
));
322+
'Request timeout after ${requestTimeout!.inMilliseconds}ms'));
323323
}
324324
}
325325
}
326326
});
327-
327+
328328
// Handle the actual request completion
329329
requestFuture.then((streamResponse) {
330330
timeoutTimer?.cancel();
@@ -337,7 +337,7 @@ class InterceptedClient extends BaseClient {
337337
completer.completeError(error);
338338
}
339339
});
340-
340+
341341
stream = await completer.future;
342342
}
343343

lib/models/retry_policy.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class RetryPolicy {
4040
///
4141
/// [reason] - The exception that occurred during the request
4242
/// [request] - The original request that failed
43-
///
43+
///
4444
/// Returns `true` if the request should be retried, `false` otherwise.
4545
FutureOr<bool> shouldAttemptRetryOnException(
4646
Exception reason, BaseRequest request) =>
@@ -50,21 +50,21 @@ abstract class RetryPolicy {
5050
/// received `response` from the server.
5151
///
5252
/// [response] - The response received from the server
53-
///
53+
///
5454
/// Returns `true` if the request should be retried, `false` otherwise.
5555
/// Common use cases include retrying on 401 (Unauthorized) or 500 (Server Error).
5656
FutureOr<bool> shouldAttemptRetryOnResponse(BaseResponse response) => false;
5757

5858
/// Number of maximum request attempts that can be retried.
59-
///
59+
///
6060
/// Default is 1, meaning the original request plus 1 retry attempt.
6161
/// Set to 0 to disable retries, or higher values for more retry attempts.
6262
int get maxRetryAttempts => 1;
6363

6464
/// Delay before retrying when an exception occurs.
6565
///
6666
/// [retryAttempt] - The current retry attempt number (1-based)
67-
///
67+
///
6868
/// Returns the delay duration. Default is no delay (Duration.zero).
6969
/// Consider implementing exponential backoff for production use.
7070
Duration delayRetryAttemptOnException({required int retryAttempt}) =>
@@ -73,7 +73,7 @@ abstract class RetryPolicy {
7373
/// Delay before retrying when a response indicates retry is needed.
7474
///
7575
/// [retryAttempt] - The current retry attempt number (1-based)
76-
///
76+
///
7777
/// Returns the delay duration. Default is no delay (Duration.zero).
7878
/// Consider implementing exponential backoff for production use.
7979
Duration delayRetryAttemptOnResponse({required int retryAttempt}) =>

lib/utils/query_parameters.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ String buildUrlString(String url, Map<String, dynamic>? parameters) {
1111
// Validate URL structure to prevent injection
1212
// First check if it looks like a valid HTTP/HTTPS URL
1313
if (!url.startsWith('http://') && !url.startsWith('https://')) {
14-
throw ArgumentError('Invalid URL structure: $url - must be a valid HTTP/HTTPS URL');
14+
throw ArgumentError(
15+
'Invalid URL structure: $url - must be a valid HTTP/HTTPS URL',
16+
);
1517
}
16-
18+
1719
try {
1820
final uri = Uri.parse(url);
1921
// Additional validation: ensure it has a host
2022
if (uri.host.isEmpty) {
21-
throw ArgumentError('Invalid URL structure: $url - must have a valid host');
23+
throw ArgumentError(
24+
'Invalid URL structure: $url - must have a valid host',
25+
);
2226
}
2327
} catch (e) {
2428
if (e is ArgumentError) {
@@ -38,15 +42,16 @@ String buildUrlString(String url, Map<String, dynamic>? parameters) {
3842
parameters.forEach((key, value) {
3943
// Encode the key to prevent injection
4044
final encodedKey = Uri.encodeQueryComponent(key);
41-
45+
4246
if (value is List) {
4347
if (value is List<String>) {
4448
for (String singleValue in value) {
4549
url += "$encodedKey=${Uri.encodeQueryComponent(singleValue)}&";
4650
}
4751
} else {
4852
for (dynamic singleValue in value) {
49-
url += "$encodedKey=${Uri.encodeQueryComponent(singleValue.toString())}&";
53+
url +=
54+
"$encodedKey=${Uri.encodeQueryComponent(singleValue.toString())}&";
5055
}
5156
}
5257
} else if (value is String) {

test/utils/utils_test.dart

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ main() {
1212
String parameterUrl = buildUrlString(url, parameters);
1313

1414
// Assert
15-
expect(parameterUrl,
16-
equals("https://www.google.com/helloworld?foo=bar&num=0"));
15+
expect(
16+
parameterUrl,
17+
equals("https://www.google.com/helloworld?foo=bar&num=0"),
18+
);
1719
});
1820
test("Adds parameters to a URL string with parameters", () {
1921
// Arrange
@@ -25,9 +27,11 @@ main() {
2527

2628
// Assert
2729
expect(
28-
parameterUrl,
29-
equals(
30-
"https://www.google.com/helloworld?foo=bar&num=0&extra=1&extra2=anotherone"));
30+
parameterUrl,
31+
equals(
32+
"https://www.google.com/helloworld?foo=bar&num=0&extra=1&extra2=anotherone",
33+
),
34+
);
3135
});
3236
test("Adds parameters with array to a URL string without parameters", () {
3337
// Arrange
@@ -41,10 +45,12 @@ main() {
4145
String parameterUrl = buildUrlString(url, parameters);
4246

4347
// Assert
44-
expect(parameterUrl,
45-
equals("https://www.google.com/helloworld?foo=bar&num=0&num=1"));
48+
expect(
49+
parameterUrl,
50+
equals("https://www.google.com/helloworld?foo=bar&num=0&num=1"),
51+
);
4652
});
47-
53+
4854
test("Properly encodes parameter keys to prevent injection", () {
4955
// Arrange
5056
String url = "https://www.google.com/helloworld";
@@ -58,30 +64,41 @@ main() {
5864

5965
// Assert
6066
expect(parameterUrl, contains("normal_key=normal_value"));
61-
expect(parameterUrl, contains(Uri.encodeQueryComponent("key&with=special")));
62-
expect(parameterUrl, contains(Uri.encodeQueryComponent("value&with=special")));
67+
expect(
68+
parameterUrl,
69+
contains(Uri.encodeQueryComponent("key&with=special")),
70+
);
71+
expect(
72+
parameterUrl,
73+
contains(Uri.encodeQueryComponent("value&with=special")),
74+
);
6375
// Should not contain unencoded special characters that could cause injection
6476
expect(parameterUrl.split('?')[1], isNot(contains("&with=special&")));
6577
});
66-
78+
6779
test("Validates URL structure and throws error for invalid URLs", () {
6880
// Arrange
6981
String invalidUrl = "not a valid url";
7082
Map<String, dynamic> parameters = {"key": "value"};
7183

7284
// Act & Assert
73-
expect(() => buildUrlString(invalidUrl, parameters),
74-
throwsA(isA<ArgumentError>()));
85+
expect(
86+
() => buildUrlString(invalidUrl, parameters),
87+
throwsA(isA<ArgumentError>()),
88+
);
7589
});
76-
77-
test("Validates URL structure and throws error for URLs without scheme", () {
90+
91+
test("Validates URL structure and throws error for URLs without scheme",
92+
() {
7893
// Arrange
7994
String invalidUrl = "example.com/path"; // No scheme
8095
Map<String, dynamic> parameters = {"key": "value"};
8196

8297
// Act & Assert
83-
expect(() => buildUrlString(invalidUrl, parameters),
84-
throwsA(isA<ArgumentError>()));
98+
expect(
99+
() => buildUrlString(invalidUrl, parameters),
100+
throwsA(isA<ArgumentError>()),
101+
);
85102
});
86103
});
87104
}

0 commit comments

Comments
 (0)