mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
modify core http_service
This commit is contained in:
@@ -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] =
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ dependencies:
|
||||
path: ../insomnia_collection
|
||||
seed: ^0.0.3
|
||||
xml: ^6.3.0
|
||||
json5: ^0.8.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user