modify core http_service

This commit is contained in:
FreeBono
2025-02-26 22:47:55 +09:00
parent 4da5a49f44
commit 717c888f9e
7 changed files with 21 additions and 15 deletions

View File

@@ -41,7 +41,10 @@ Future<(HttpResponse?, Duration?, String?)> sendHttpRequest(
if (kMethodsWithBody.contains(requestModel.method)) {
var requestBody = requestModel.body;
if (requestBody != null && !isMultiPartRequest) {
var contentLength = utf8.encode(requestBody).length;
if (requestModel.hasJsonData) {
requestBody = removeJsonComments(requestBody);
}
var contentLength = utf8.encode(requestBody!).length;
if (contentLength > 0) {
body = requestBody;
headers[HttpHeaders.contentLengthHeader] =

View File

@@ -1,8 +1,11 @@
import 'dart:convert';
import 'package:apidash_core/consts.dart';
import 'package:collection/collection.dart';
import 'package:seed/seed.dart';
import '../models/models.dart';
import 'graphql_utils.dart';
import 'package:json5/json5.dart' as json5;
Map<String, String>? rowsToMap(
List<NameValueModel>? kvRows, {
@@ -101,3 +104,14 @@ String? getRequestBody(APIType type, HttpRequestModel httpRequestModel) {
APIType.graphql => getGraphQLBody(httpRequestModel),
};
}
String? removeJsonComments(String? json) {
try {
if (json == null) return null;
var parsed = json5.json5Decode(json);
return kJsonEncoder.convert(parsed);
} catch (e) {
return json;
}
}

View File

@@ -23,6 +23,7 @@ dependencies:
path: ../insomnia_collection
seed: ^0.0.3
xml: ^6.3.0
json5: ^0.8.2
dev_dependencies:
flutter_test: