From 693b4bda70449d411d8debc50906ce487f7170d9 Mon Sep 17 00:00:00 2001 From: Tanish2002 Date: Fri, 23 Feb 2024 13:50:29 +0530 Subject: [PATCH 1/2] fix: remove redundant body payload from codegen --- lib/codegen/python/http_client.dart | 4 +++- lib/codegen/python/requests.dart | 2 +- lib/utils/har_utils.dart | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/codegen/python/http_client.dart b/lib/codegen/python/http_client.dart index 4406effb..196b10df 100644 --- a/lib/codegen/python/http_client.dart +++ b/lib/codegen/python/http_client.dart @@ -130,7 +130,9 @@ body = b'\r\n'.join(dataList) var method = requestModel.method; var requestBody = requestModel.requestBody; - if (kMethodsWithBody.contains(method) && requestBody != null) { + if (kMethodsWithBody.contains(method) && + requestBody != null && + !requestModel.isFormDataRequest) { var contentLength = utf8.encode(requestBody).length; if (contentLength > 0) { hasBody = true; diff --git a/lib/codegen/python/requests.dart b/lib/codegen/python/requests.dart index 3a5beeb6..cd79ccde 100644 --- a/lib/codegen/python/requests.dart +++ b/lib/codegen/python/requests.dart @@ -140,7 +140,7 @@ print('Response Body:', response.text) hasJsonBody = true; var templateBody = jj.Template(kTemplateJson); result += templateBody.render({"body": requestBody}); - } else { + } else if (!requestModel.isFormDataRequest) { hasBody = true; var templateBody = jj.Template(kTemplateBody); result += templateBody.render({"body": requestBody}); diff --git a/lib/utils/har_utils.dart b/lib/utils/har_utils.dart index 38913c6e..b5e1de72 100644 --- a/lib/utils/har_utils.dart +++ b/lib/utils/har_utils.dart @@ -112,7 +112,9 @@ Map requestModelToHARJsonRequest( var method = requestModel.method; var requestBody = requestModel.requestBody; - if (kMethodsWithBody.contains(method) && requestBody != null) { + if (kMethodsWithBody.contains(method) && + requestBody != null && + !requestModel.isFormDataRequest) { var contentLength = utf8.encode(requestBody).length; if (contentLength > 0) { hasBody = true; From bff2ca892dbaeb39df4147f21893aded4f70a1b0 Mon Sep 17 00:00:00 2001 From: Tanish2002 Date: Fri, 23 Feb 2024 19:19:32 +0530 Subject: [PATCH 2/2] fix: redundant dart(http) codegen --- lib/codegen/dart/http.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/codegen/dart/http.dart b/lib/codegen/dart/http.dart index 3e423743..42c44ecb 100644 --- a/lib/codegen/dart/http.dart +++ b/lib/codegen/dart/http.dart @@ -53,7 +53,9 @@ class DartHttpCodeGen { declareVar('uri').assign(refer('Uri.parse').call([literalString(url)])); Expression? dataExp; - if (kMethodsWithBody.contains(method) && (body?.isNotEmpty ?? false)) { + if (kMethodsWithBody.contains(method) && + (body?.isNotEmpty ?? false) && + contentType != ContentType.formdata) { final strContent = CodeExpression(Code('r\'\'\'$body\'\'\'')); dataExp = declareVar('body', type: refer('String')).assign(strContent); if (!hasContentTypeHeader) {