mirror of
https://github.com/foss42/apidash.git
synced 2026-03-13 09:50:32 +08:00
http v1.6.0 breaking change: charset parameter is not added for json
This commit is contained in:
@@ -119,7 +119,6 @@ Future<(HttpResponse?, Duration?, String?)> sendHttpRequestV1(
|
||||
method: authenticatedRequestModel.method.name.toUpperCase(),
|
||||
headers: headers,
|
||||
body: body,
|
||||
overrideContentType: overrideContentType,
|
||||
);
|
||||
final streamed = await client.send(request);
|
||||
response = await http.Response.fromStream(streamed);
|
||||
@@ -182,20 +181,12 @@ http.Request prepareHttpRequest({
|
||||
required String method,
|
||||
required Map<String, String> headers,
|
||||
required String? body,
|
||||
bool overrideContentType = false,
|
||||
}) {
|
||||
var request = http.Request(method, url);
|
||||
if (headers.getValueContentType() != null) {
|
||||
request.headers[HttpHeaders.contentTypeHeader] = headers
|
||||
.getValueContentType()!;
|
||||
if (!overrideContentType) {
|
||||
headers.removeKeyContentType();
|
||||
}
|
||||
}
|
||||
if (body != null) {
|
||||
request.body = body;
|
||||
headers[HttpHeaders.contentLengthHeader] = request.bodyBytes.length
|
||||
.toString();
|
||||
headers[HttpHeaders.contentLengthHeader] =
|
||||
request.bodyBytes.length.toString();
|
||||
}
|
||||
request.headers.addAll(headers);
|
||||
return request;
|
||||
@@ -398,7 +389,6 @@ Future<http.StreamedResponse> makeStreamedRequest({
|
||||
method: requestModel.method.name.toUpperCase(),
|
||||
headers: headers,
|
||||
body: body,
|
||||
overrideContentType: overrideContentType,
|
||||
);
|
||||
streamedResponse = await client.send(request);
|
||||
}
|
||||
|
||||
@@ -192,30 +192,31 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('Testing overrideContentType functionality', () {
|
||||
group(
|
||||
'Testing overrideContentType functionality not required due to http v1.6.0 breaking change',
|
||||
() {
|
||||
test('overrideContentType is true', () async {
|
||||
final request = prepareHttpRequest(
|
||||
url: Uri.parse('https://www.example.com'),
|
||||
method: 'POST',
|
||||
body: 'Hello',
|
||||
headers: {'content-type': 'application/json'},
|
||||
overrideContentType: true,
|
||||
);
|
||||
expect(request.headers['content-type'], 'application/json');
|
||||
});
|
||||
|
||||
test('overrideContentType is false', () async {
|
||||
test('; charset=utf-8 is not appended due to http v1.6.0 breaking change',
|
||||
() async {
|
||||
final request = prepareHttpRequest(
|
||||
url: Uri.parse('https://www.example.com'),
|
||||
method: 'POST',
|
||||
body: 'Hello',
|
||||
headers: {'content-type': 'application/json'},
|
||||
overrideContentType: false,
|
||||
);
|
||||
expect(request.headers['content-type'], isNot('application/json'));
|
||||
expect(request.headers['content-type'], 'application/json');
|
||||
expect(
|
||||
request.headers['content-type'],
|
||||
'application/json; charset=utf-8',
|
||||
isNot('application/json; charset=utf-8'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user