http icon indicating copy to clipboard operation
http copied to clipboard

Make BaseRequest clonable

Open 0ttik opened this issue 4 years ago • 4 comments

It seems that this feature was never delivered. It makes me either implement my own instance of Request and deal with lots of shenanigans or fork your library, which seems kinda strange for such a basic feature.

https://github.com/dart-lang/http/issues/103

0ttik avatar Sep 30 '21 15:09 0ttik

If Response had something like this, would it be useful?

@0ttik

  Response copyWith({
    int? statusCode,
    BaseRequest? request,
    Map<String, String>? headers,
    bool? isRedirect,
    bool? persistentConnection,
    String? reasonPhrase,
    List<int>? bodyBytes,
  }) =>
      Response.bytes(
        bodyBytes ?? this.bodyBytes,
        statusCode ?? this.statusCode,
        request: request ?? this.request,
        headers: headers ?? this.headers,
        isRedirect: isRedirect ?? this.isRedirect,
        persistentConnection: persistentConnection ?? this.persistentConnection,
        reasonPhrase: reasonPhrase ?? this.reasonPhrase,
      );

MelbourneDeveloper avatar Sep 16 '22 06:09 MelbourneDeveloper

@MelbourneDeveloper, yes it would be great. Nowdays we can deal with it using extensions, but still.

0ttik avatar Sep 16 '22 06:09 0ttik

Which extensions do you use? @0ttik ?

MelbourneDeveloper avatar Sep 17 '22 21:09 MelbourneDeveloper

just

extension Bamboozle on Response {
  Response copyWith({
      int? statusCode,
      BaseRequest? request,
      Map<String, String>? headers,
      bool? isRedirect,
      bool? persistentConnection,
      String? reasonPhrase,
      List<int>? bodyBytes,
    }) =>
        Response.bytes(
          bodyBytes ?? this.bodyBytes,
          statusCode ?? this.statusCode,
          request: request ?? this.request,
          headers: headers ?? this.headers,
          isRedirect: isRedirect ?? this.isRedirect,
          persistentConnection: persistentConnection ?? this.persistentConnection,
          reasonPhrase: reasonPhrase ?? this.reasonPhrase,
        );
}

0ttik avatar Sep 17 '22 21:09 0ttik