49 lines
1.7 KiB
Dart

// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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';
/// {@template middleware}
/// A middleware is a class that can intercept requests and responses
/// and modify them before they are sent to the server or before they
/// are returned to the client.
/// {@endtemplate}
abstract class Middleware {
/// {@macro middleware}
const Middleware();
/// The name of the middleware.
String getName();
}
mixin OnRequestMiddleware {
/// Performs an action before the request is sent to the server.
Future<MiddlewareRequest> onRequest(
MiddlewareContext context,
MiddlewareRequest request,
);
}
mixin OnResponseMiddleware {
/// Performs an action before the response is returned to the client.
Future<MiddlewareResponse> onResponse(
MiddlewareContext context,
MiddlewareResponse response,
);
}