@@ -32,43 +32,40 @@ extension BaseResponseCopyWith on BaseResponse {
3232 int ? contentLength,
3333 // `IOStreamedResponse` only properties.
3434 HttpClientResponse ? inner,
35- }) {
36- if (this is Response ) {
37- return ResponseCopyWith (this as Response ).copyWith (
38- statusCode: statusCode,
39- body: body,
40- request: request,
41- headers: headers,
42- isRedirect: isRedirect,
43- persistentConnection: persistentConnection,
44- reasonPhrase: reasonPhrase,
45- );
46- } else if (this is StreamedResponse ) {
47- return StreamedResponseCopyWith (this as StreamedResponse ).copyWith (
48- stream: stream,
49- statusCode: statusCode,
50- contentLength: contentLength,
51- request: request,
52- headers: headers,
53- isRedirect: isRedirect,
54- persistentConnection: persistentConnection,
55- reasonPhrase: reasonPhrase,
56- );
57- } else if (this is IOStreamedResponse ) {
58- return IOStreamedResponseCopyWith (this as IOStreamedResponse ).copyWith (
59- stream: stream,
60- statusCode: statusCode,
61- contentLength: contentLength,
62- request: request,
63- headers: headers,
64- isRedirect: isRedirect,
65- persistentConnection: persistentConnection,
66- reasonPhrase: reasonPhrase,
67- inner: inner,
68- );
69- }
70-
71- throw UnsupportedError (
72- 'Cannot copy unsupported type of response $runtimeType ' );
73- }
35+ }) =>
36+ switch (this ) {
37+ Response res => res.copyWith (
38+ statusCode: statusCode,
39+ body: body,
40+ request: request,
41+ headers: headers,
42+ isRedirect: isRedirect,
43+ persistentConnection: persistentConnection,
44+ reasonPhrase: reasonPhrase,
45+ ),
46+ IOStreamedResponse res => res.copyWith (
47+ stream: stream,
48+ statusCode: statusCode,
49+ contentLength: contentLength,
50+ request: request,
51+ headers: headers,
52+ isRedirect: isRedirect,
53+ persistentConnection: persistentConnection,
54+ reasonPhrase: reasonPhrase,
55+ inner: inner,
56+ ),
57+ StreamedResponse res => res.copyWith (
58+ stream: stream,
59+ statusCode: statusCode,
60+ contentLength: contentLength,
61+ request: request,
62+ headers: headers,
63+ isRedirect: isRedirect,
64+ persistentConnection: persistentConnection,
65+ reasonPhrase: reasonPhrase,
66+ ),
67+ _ => throw UnsupportedError (
68+ 'Cannot copy unsupported type of response $runtimeType ' ,
69+ ),
70+ };
7471}
0 commit comments