You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,16 @@
1
1
# Changelog
2
2
3
+
## 3.0.0
4
+
5
+
-**Breaking**: Rebuild from scratch. Not backwards compatible with 2.x.
6
+
-**Added**: `HttpInterceptor` interface (replaces `InterceptorContract`). Same four methods with `FutureOr` support.
7
+
-**Added**: `InterceptedClient.build(...)` and `InterceptedHttp.build(...)` with `interceptors`, `client`, `retryPolicy`, `requestTimeout`, `onRequestTimeout`.
8
+
-**Added**: Optional `params` and `paramsAll` on `get`, `post`, `put`, `patch`, `delete`, `head`; merged into URL query.
Copy file name to clipboardExpand all lines: README.md
+42-95Lines changed: 42 additions & 95 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ This is a plugin that lets you intercept the different requests and responses fr
18
18
19
19
## Quick Reference
20
20
21
-
**Already using `http_interceptor`? Check out the [1.0.0 migration guide](./guides/migration_guide_1.0.0.md) for quick reference on the changes made and how to migrate your code.**
21
+
**Upgrading from 2.x? See the [3.0.0 migration guide](./guides/migration_guide_3.0.0.md).**
22
22
23
23
-[http\_interceptor](#http_interceptor)
24
24
-[Quick Reference](#quick-reference)
@@ -51,7 +51,7 @@ http_interceptor: <latest>
51
51
- 🚦 Intercept & change unstreamed requests and responses.
52
52
- ✨ Retrying requests when an error occurs or when the response does not match the desired (useful for handling custom error responses).
53
53
- 👓 `GET` requests with separated parameters.
54
-
- ⚡️ Standard `bodyBytes`on `ResponseData` to encode or decode in the desired format.
54
+
- ⚡️ Standard `Response.bodyBytes`for encoding or decoding as needed.
55
55
- 🙌🏼 Array parameters on requests.
56
56
- 🖋 Supports self-signed certificates (except on Flutter Web).
57
57
- 🍦 Compatible with vanilla Dart projects or Flutter projects.
In order to implement `http_interceptor` you need to implement the `InterceptorContract` and create your own interceptor. This abstract class has four methods:
70
+
Implement `HttpInterceptor` to add logging, headers, error handling, and more. The interface has four methods:
71
71
72
-
-`interceptRequest`, which triggers before the http request is called
73
-
-`interceptResponse`, which triggers after the request is called, it has a response attached to it which the corresponding to said request;
74
-
75
-
-`shouldInterceptRequest` and `shouldInterceptResponse`, which are used to determine if the request or response should be intercepted or not. These two methods are optional as they return `true` by default, but they can be useful if you want to conditionally intercept requests or responses based on certain criteria.
72
+
-**interceptRequest** – runs before the request is sent. Return the (possibly modified) request.
73
+
-**interceptResponse** – runs after the response is received. Return the (possibly modified) response.
74
+
-**shouldInterceptRequest** / **shouldInterceptResponse** – return `false` to skip interception for that request/response (default `true`).
76
75
77
-
You could use this package to do logging, adding headers, error handling, or many other cool stuff. It is important to note that after you proccess the request/response objects you need to return them so that `http` can continue the execute.
76
+
All methods support `FutureOr` so you can use sync or async. Modify the request/response in place and return it, or return a new instance.
78
77
79
-
All four methods use `FutureOr` syntax, which makes it easier to support both synchronous and asynchronous behaviors.
80
-
81
-
- Logging with interceptor:
78
+
- Logging interceptor:
82
79
83
80
```dart
84
-
class LoggerInterceptor extends InterceptorContract {
81
+
class LoggerInterceptor implements HttpInterceptor {
<!-- Explain the overall context of the decision, the problem it attempts to solve, examples of why it might need solving. You can even add possible solutions -->
11
+
12
+
## Decision
13
+
14
+
<!-- Explain the decision that was taken. Why it was taken -->
15
+
16
+
## Consequences
17
+
18
+
<!-- Describe the consequences of this decision, deprecations, new features, removed code, etc. -->
The library was initally a rewrite of [http_middleware](https://pub.dev/packages/http_middleware). It has reached 2.0.0 with a full feature set (interceptors, retry, timeout, copyWith on requests/responses, query params, etc.). However, the existing implementation had accumulated complexity and made a clean evolution difficult. A from-scratch rebuild was chosen to:
10
+
11
+
- Apply the principles, design patterns, and best practices.
12
+
- Avoid inheriting code smells and anti-patterns from the previous implementation.
13
+
- Prioritize a small API surface and clear behavior over backwards compatibility with 2.x.
14
+
15
+
The 2.0.0 API was used as a feature and API reference only; no backwards compatibility with 2.x is required.
16
+
17
+
## Decision
18
+
19
+
Rebuild the library as version 3 with the following decisions:
20
+
21
+
-**Decorator pattern**: The intercepted client wraps a `Client`, implements `Client`, and delegates to the inner client while adding interception. New behavior is added by composition (interceptors, retry, timeout), not by one large class.
22
+
-**Strategy pattern**: Interceptors define how to transform request/response; `RetryPolicy` defines when to retry and with what delay. Both are injectable strategies.
23
+
-**No copyWith in core**: Interceptors receive and return `BaseRequest`/`BaseResponse` from `package:http`. The supported pattern is in-place mutation or returning the same instance. Cloning (copyWith) was not added to the core API to keep the library simple; it can be a code smell (many clone surfaces). Importantly, `StreamedRequest` and `StreamedResponse` carry streams, which can be consumed only once—you cannot meaningfully “copy” a stream. A copyWith for those types would therefore be either limited (e.g. only URL and headers) or error-prone (e.g. reusing or re-wrapping the same stream). That constraint makes a uniform copyWith story across all request/response types fragile and reinforces the decision to avoid it in core.
24
+
-**Small composable units**: Interceptor chain runner, retry executor, and timeout wrapper are separate, testable units. The client’s `send()` orchestrates them in a clear order: request interceptors → (optional) timeout → send → response interceptors; retry re-runs from request interceptors when the policy allows.
25
+
-**InterceptedClient and InterceptedHttp**: `InterceptedClient` extends `BaseClient` and overrides `send()`; `InterceptedHttp` is a facade that holds an `InterceptedClient` and exposes `get`, `post`, etc., plus optional `close()`.
26
+
-**Single interceptor and retry abstractions**: One `HttpInterceptor` interface and one `RetryPolicy` interface; avoid overlapping or redundant abstractions (YAGNI).
27
+
28
+
## Consequences
29
+
30
+
-**Removed**: Backwards compatibility with 2.x; `RequestData`/`ResponseData`; copyWith in the core API; any structure or naming copied from the deleted implementation.
31
+
-**Added**: Clean implementation under `lib/src/` with interceptors, chain, retry, timeout, and client/facade; alignment with Decorator/Strategy and SOLID; guard clauses and linear control flow where possible.
32
+
-**Preserved (conceptually)**: Interceptor contract (intercept request/response, shouldIntercept flags), retry policy (on exception and on response, configurable delay), request timeout and callback, query params (`params`/`paramsAll`) on convenience methods, Uri and String extensions where they fit the minimal API.
33
+
-**Documentation**: Migration guide (e.g. [migration_guide_3.0.0.md](../../guides/migration_guide_3.0.0.md)) explains the break from 2.x and how to migrate (e.g. work with `BaseRequest`/`BaseResponse`, no copyWith).
0 commit comments