refactor(http)!: fix cascade dart good practices + docs

This commit is contained in:
2023-04-13 23:29:27 +02:00
parent 216a6c2aae
commit 07c2f4aeff
33 changed files with 303 additions and 974 deletions
@@ -1,4 +1,3 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
@@ -22,24 +21,43 @@ import 'package:wyatt_http_client/src/models/unfreezed_request.dart';
import 'package:wyatt_http_client/src/utils/convert.dart';
import 'package:wyatt_http_client/src/utils/request_utils.dart';
/// {@template middleware_request}
/// A class that represents a middleware request.
/// {@endtemplate}
class MiddlewareRequest {
UnfreezedRequest unfreezedRequest;
Request _httpRequest;
Request get request => _httpRequest;
// Proxy
String get method => _httpRequest.method;
Uri get url => _httpRequest.url;
Map<String, String> get headers => _httpRequest.headers;
Encoding get encoding => _httpRequest.encoding;
String get encodedBody => _httpRequest.body;
Object? get body => unfreezedRequest.body;
/// {@macro middleware_request}
MiddlewareRequest({
required this.unfreezedRequest,
}) : _httpRequest = Request(unfreezedRequest.method, unfreezedRequest.url);
/// The unfreezed request.
UnfreezedRequest unfreezedRequest;
Request _httpRequest;
/// The http request. (Read-only)
Request get request => _httpRequest;
/// The request method (proxy, read-only).
String get method => _httpRequest.method;
/// The request url (proxy, read-only).
Uri get url => _httpRequest.url;
/// The request headers (proxy, read-only).
Map<String, String> get headers => _httpRequest.headers;
/// The request body (proxy, read-only).
Encoding get encoding => _httpRequest.encoding;
/// The request body (proxy, read-only).
String get encodedBody => _httpRequest.body;
/// The request body (proxy, read-only).
Object? get body => unfreezedRequest.body;
/// Copies this request and returns a new request with the given
/// [unfreezedRequest].
MiddlewareRequest copyWith({
UnfreezedRequest? unfreezedRequest,
}) =>
@@ -47,6 +65,7 @@ class MiddlewareRequest {
unfreezedRequest: unfreezedRequest ?? this.unfreezedRequest,
);
/// Modifies the request with the given [unfreezedRequest].
void modifyRequest(UnfreezedRequest unfreezedRequest) {
String? body;
if (unfreezedRequest.body != null) {
@@ -72,6 +91,8 @@ class MiddlewareRequest {
this.unfreezedRequest = unfreezedRequest;
}
/// Applies the changes made to the request by modifying it with the
/// [unfreezedRequest].
void apply() {
modifyRequest(unfreezedRequest);
}