mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 18:57:05 +08:00
modify core http_service
This commit is contained in:
@@ -74,7 +74,7 @@ class EditRequestBody extends ConsumerWidget {
|
||||
|
||||
ref
|
||||
.read(collectionStateNotifierProvider.notifier)
|
||||
.update(body: removeJsonComments(value));
|
||||
.update(body: value);
|
||||
},
|
||||
hintText: kHintJson,
|
||||
),
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:convert';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:json5/json5.dart' as json5;
|
||||
|
||||
String humanizeDate(DateTime? date) {
|
||||
if (date == null) {
|
||||
@@ -84,12 +82,3 @@ Uint8List jsonMapToBytes(Map<String, dynamic>? map) {
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
String removeJsonComments(String json) {
|
||||
try {
|
||||
var parsed = json5.json5Decode(json);
|
||||
return jsonEncode(parsed);
|
||||
} catch (e) {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -809,7 +809,7 @@ packages:
|
||||
source: hosted
|
||||
version: "0.7.1"
|
||||
json5:
|
||||
dependency: "direct main"
|
||||
dependency: transitive
|
||||
description:
|
||||
name: json5
|
||||
sha256: b67d6e06c9e225c8277d3c43f796677af7975a2a2b0669ff12ba38ff466a31f4
|
||||
|
||||
@@ -66,7 +66,6 @@ dependencies:
|
||||
url: https://github.com/google/flutter-desktop-embedding.git
|
||||
path: plugins/window_size
|
||||
share_plus: ^10.1.4
|
||||
json5: ^0.8.2
|
||||
|
||||
dependency_overrides:
|
||||
extended_text_field: ^16.0.0
|
||||
|
||||
Reference in New Issue
Block a user