Skip to content

Commit 717c888

Browse files
committed
modify core http_service
1 parent 4da5a49 commit 717c888

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class EditRequestBody extends ConsumerWidget {
7474

7575
ref
7676
.read(collectionStateNotifierProvider.notifier)
77-
.update(body: removeJsonComments(value));
77+
.update(body: value);
7878
},
7979
hintText: kHintJson,
8080
),

lib/utils/convert_utils.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import 'dart:typed_data';
22
import 'dart:convert';
33
import 'package:apidash_core/apidash_core.dart';
4-
import 'package:flutter/material.dart';
54
import 'package:intl/intl.dart';
6-
import 'package:json5/json5.dart' as json5;
75

86
String humanizeDate(DateTime? date) {
97
if (date == null) {
@@ -84,12 +82,3 @@ Uint8List jsonMapToBytes(Map<String, dynamic>? map) {
8482
return bytes;
8583
}
8684
}
87-
88-
String removeJsonComments(String json) {
89-
try {
90-
var parsed = json5.json5Decode(json);
91-
return jsonEncode(parsed);
92-
} catch (e) {
93-
return json;
94-
}
95-
}

packages/apidash_core/lib/services/http_service.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ Future<(HttpResponse?, Duration?, String?)> sendHttpRequest(
4141
if (kMethodsWithBody.contains(requestModel.method)) {
4242
var requestBody = requestModel.body;
4343
if (requestBody != null && !isMultiPartRequest) {
44-
var contentLength = utf8.encode(requestBody).length;
44+
if (requestModel.hasJsonData) {
45+
requestBody = removeJsonComments(requestBody);
46+
}
47+
var contentLength = utf8.encode(requestBody!).length;
4548
if (contentLength > 0) {
4649
body = requestBody;
4750
headers[HttpHeaders.contentLengthHeader] =

packages/apidash_core/lib/utils/http_request_utils.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import 'dart:convert';
2+
13
import 'package:apidash_core/consts.dart';
24
import 'package:collection/collection.dart';
35
import 'package:seed/seed.dart';
46
import '../models/models.dart';
57
import 'graphql_utils.dart';
8+
import 'package:json5/json5.dart' as json5;
69

710
Map<String, String>? rowsToMap(
811
List<NameValueModel>? kvRows, {
@@ -101,3 +104,14 @@ String? getRequestBody(APIType type, HttpRequestModel httpRequestModel) {
101104
APIType.graphql => getGraphQLBody(httpRequestModel),
102105
};
103106
}
107+
108+
String? removeJsonComments(String? json) {
109+
try {
110+
if (json == null) return null;
111+
112+
var parsed = json5.json5Decode(json);
113+
return kJsonEncoder.convert(parsed);
114+
} catch (e) {
115+
return json;
116+
}
117+
}

packages/apidash_core/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies:
2323
path: ../insomnia_collection
2424
seed: ^0.0.3
2525
xml: ^6.3.0
26+
json5: ^0.8.2
2627

2728
dev_dependencies:
2829
flutter_test:

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ packages:
809809
source: hosted
810810
version: "0.7.1"
811811
json5:
812-
dependency: "direct main"
812+
dependency: transitive
813813
description:
814814
name: json5
815815
sha256: b67d6e06c9e225c8277d3c43f796677af7975a2a2b0669ff12ba38ff466a31f4

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ dependencies:
6666
url: https://github.com/google/flutter-desktop-embedding.git
6767
path: plugins/window_size
6868
share_plus: ^10.1.4
69-
json5: ^0.8.2
7069

7170
dependency_overrides:
7271
extended_text_field: ^16.0.0

0 commit comments

Comments
 (0)