diff --git a/lib/codegen/dart/http.dart b/lib/codegen/dart/http.dart index 67184c25..602b9a73 100644 --- a/lib/codegen/dart/http.dart +++ b/lib/codegen/dart/http.dart @@ -55,8 +55,11 @@ class DartHttpCodeGen { final strContent = CodeExpression(Code('r\'\'\'$body\'\'\'')); dataExp = declareVar('body', type: refer('String')).assign(strContent); - composeHeaders.putIfAbsent(HttpHeaders.contentTypeHeader, + final hasContentTypeHeader = composeHeaders.keys.any((k) => k.toLowerCase() == HttpHeaders.contentTypeHeader); + if (!hasContentTypeHeader) { + composeHeaders.putIfAbsent(HttpHeaders.contentTypeHeader, () => kContentTypeMap[contentType] ?? ''); + } } Expression? queryParamExp; diff --git a/lib/codegen/python/http_client.dart b/lib/codegen/python/http_client.dart index 83d02676..27f35380 100644 --- a/lib/codegen/python/http_client.dart +++ b/lib/codegen/python/http_client.dart @@ -102,7 +102,9 @@ print(data.decode("utf-8")) var headers = requestModel.headersMap; if (headers.isNotEmpty || hasBody) { hasHeaders = true; - if (hasBody) { + bool hasContentTypeHeader = headers.keys.any((k) => k.toLowerCase() == HttpHeaders.contentTypeHeader); + + if (hasBody && !hasContentTypeHeader) { headers[HttpHeaders.contentTypeHeader] = kContentTypeMap[requestModel.requestBodyContentType] ?? ""; } diff --git a/lib/utils/har_utils.dart b/lib/utils/har_utils.dart index f0838807..94cdda8b 100644 --- a/lib/utils/har_utils.dart +++ b/lib/utils/har_utils.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:io'; import 'package:apidash/consts.dart'; import 'package:apidash/utils/utils.dart' show getValidRequestUri; import 'package:apidash/models/models.dart' show RequestModel; @@ -129,7 +130,9 @@ Map requestModelToHARJsonRequest( if (headersList != null || hasBody) { var headers = requestModel.headersMap; if (headers.isNotEmpty || hasBody) { - if (hasBody) { + bool hasContentTypeHeader = headers.keys.any((k) => k.toLowerCase() == HttpHeaders.contentTypeHeader); + + if (hasBody && !hasContentTypeHeader) { var m = { "name": "Content-Type", "value": kContentTypeMap[requestModel.requestBodyContentType] ?? ""