Skip to content

Commit 50b5be3

Browse files
authored
fix: copywith missing fields (#103)
* fix: add missing fields in copyWith * chore: cleanup * test: updated tests * ver: 2.0.0-beta.3
1 parent 47a9c1b commit 50b5be3

File tree

12 files changed

+29
-23
lines changed

12 files changed

+29
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.0.0-beta.3
4+
5+
- 🐞  Fixed: `copyWith` was missing fields
6+
- 🚦  Tests: Updated tests.
7+
38
## 2.0.0-beta.1
49

510
- ❗️🛠  Changed: Renamed `Method` to use `HttpMethod` and refactored helper functions into extensions (`StringToMethod`, and `MethodToString`).

example/lib/main.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import 'dart:developer';
33
import 'dart:io';
44

55
import 'package:flutter/material.dart';
6-
import 'package:http/src/base_request.dart';
7-
import 'package:http/src/base_response.dart';
86
import 'package:http_interceptor/http_interceptor.dart';
97
import 'package:shared_preferences/shared_preferences.dart';
108

lib/extensions/multipart_request.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ extension MultipartRequestCopyWith on MultipartRequest {
1919
method?.asString ?? this.method,
2020
url ?? this.url,
2121
)
22-
..headers.addAll(headers ?? {})
23-
..fields.addAll(fields ?? {})
24-
..files.addAll(files ?? [])
22+
..headers.addAll(headers ?? this.headers)
23+
..fields.addAll(fields ?? this.fields)
24+
..files.addAll(files ?? this.files)
2525
..followRedirects = followRedirects ?? this.followRedirects
2626
..maxRedirects = maxRedirects ?? this.maxRedirects
2727
..persistentConnection =

lib/extensions/request.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension RequestCopyWith on Request {
2121
method?.asString ?? this.method,
2222
url ?? this.url,
2323
)
24-
..headers.addAll(headers ?? {})
24+
..headers.addAll(headers ?? this.headers)
2525
..encoding = encoding ?? this.encoding
2626
..body = body ?? this.body
2727
..followRedirects = followRedirects ?? this.followRedirects

lib/extensions/streamed_request.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension StreamedRequestCopyWith on StreamedRequest {
1818
method?.asString ?? this.method,
1919
url ?? this.url,
2020
)
21-
..headers.addAll(headers ?? {})
21+
..headers.addAll(headers ?? this.headers)
2222
..followRedirects = followRedirects ?? this.followRedirects
2323
..maxRedirects = maxRedirects ?? this.maxRedirects
2424
..persistentConnection =

lib/http/intercepted_http.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import 'dart:async';
22
import 'dart:convert';
33
import 'dart:typed_data';
44

5-
import 'package:http/http.dart';
65
import 'package:http_interceptor/http_interceptor.dart';
76

8-
import 'intercepted_client.dart';
9-
import 'interceptor_contract.dart';
10-
117
/// Class to be used by the user as a replacement for 'http' with interceptor
128
/// support.
139
///

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: http_interceptor
22
description: A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
3-
version: 2.0.0-beta.1
3+
version: 2.0.0-beta.3
44
homepage: https://github.com/CodingAleCR/http_interceptor
55
issue_tracker: https://github.com/CodingAleCR/http_interceptor/issues
66
repository: https://github.com/CodingAleCR/http_interceptor

test/extensions/base_reponse_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:http/http.dart';
21
import 'package:http_interceptor/http_interceptor.dart';
32
import 'package:test/test.dart';
43

test/extensions/base_request_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:convert';
22

3-
import 'package:http/http.dart';
43
import 'package:http_interceptor/http_interceptor.dart';
54
import 'package:test/test.dart';
65

test/extensions/request_test.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:convert';
22

3-
import 'package:http/http.dart';
43
import 'package:http_interceptor/http_interceptor.dart';
54
import 'package:test/test.dart';
65

@@ -10,7 +9,8 @@ main() {
109

1110
setUpAll(() {
1211
baseRequest = Request("GET", Uri.https("www.google.com", "/helloworld"))
13-
..body = jsonEncode(<String, String>{'some_param': 'some value'});
12+
..body = jsonEncode(<String, String>{'some_param': 'some value'})
13+
..headers['some_header'] = 'header_value';
1414
request = baseRequest as Request;
1515
});
1616

@@ -205,18 +205,23 @@ main() {
205205
test('Request is copied with different encoding', () {
206206
// Arrange
207207
final newEncoding = Encoding.getByName('latin1');
208-
final changedHeaders = {'content-type': 'text/plain; charset=iso-8859-1'};
208+
final changedHeaders = {'content-type': 'text/plain; charset=iso-8859-1'}
209+
..addAll(request.headers);
210+
211+
Request updatedHeadersRequest = request.copyWith(
212+
headers: changedHeaders,
213+
);
209214

210215
// Act
211-
Request copied = request.copyWith(
216+
Request copied = updatedHeadersRequest.copyWith(
212217
encoding: newEncoding,
213218
);
214219

215220
// Assert
216221
expect(copied.url, equals(request.url));
217222
expect(copied.method, equals(request.method));
218223
expect(copied.headers.length, equals(request.headers.length));
219-
expect(copied.headers, equals(changedHeaders));
224+
expect(updatedHeadersRequest.headers, equals(request.headers));
220225
expect(copied.body, equals(request.body));
221226
expect(
222227
copied.encoding,

0 commit comments

Comments
 (0)