feat(http): add new middleware feature

This commit is contained in:
2022-06-24 15:58:48 +02:00
parent 14cb3485e4
commit 81367e5f3a
42 changed files with 1021 additions and 2146 deletions
@@ -14,31 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
part of 'pipeline.dart';
import 'package:wyatt_http_client/src/models/middleware_context.dart';
import 'package:wyatt_http_client/src/models/middleware_request.dart';
import 'package:wyatt_http_client/src/models/middleware_response.dart';
class Middleware {
/// The http [MiddlewareClient] used by this [Middleware]
MiddlewareClient? _client;
abstract class Middleware {
Middleware();
String getName();
}
String getName() => 'MiddlewareNode';
// ignore: avoid_setters_without_getters
set httpClient(MiddlewareClient? client) => _client = client;
Client? get client => _client?.inner;
mixin OnRequestMiddleware {
Future<MiddlewareRequest> onRequest(
MiddlewareContext context,
MiddlewareRequest request,
) async {
return request;
}
Future<MiddlewareResponse> onResponse(MiddlewareResponse response) async {
return response;
}
);
}
@override
String toString() {
return getName();
}
mixin OnResponseMiddleware {
Future<MiddlewareResponse> onResponse(
MiddlewareContext context,
MiddlewareResponse response,
);
}