mirror of
https://github.com/foss42/apidash.git
synced 2025-06-02 07:46:10 +08:00
set boundary
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'package:apidash/models/models.dart' show RequestModel;
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/utils/utils.dart' show getNewUuid;
|
||||
import 'dart/http.dart';
|
||||
import 'dart/dio.dart';
|
||||
import 'kotlin/okhttp.dart';
|
||||
@ -14,8 +15,12 @@ class Codegen {
|
||||
String? getCode(
|
||||
CodegenLanguage codegenLanguage,
|
||||
RequestModel requestModel,
|
||||
String defaultUriScheme,
|
||||
) {
|
||||
String defaultUriScheme, {
|
||||
String? boundary,
|
||||
}) {
|
||||
if (requestModel.isFormDataRequest) {
|
||||
boundary = boundary ?? getNewUuid();
|
||||
}
|
||||
switch (codegenLanguage) {
|
||||
case CodegenLanguage.curl:
|
||||
return cURLCodeGen().getCode(requestModel, defaultUriScheme);
|
||||
@ -39,9 +44,10 @@ class Codegen {
|
||||
return KotlinOkHttpCodeGen().getCode(requestModel, defaultUriScheme);
|
||||
case CodegenLanguage.pythonHttpClient:
|
||||
return PythonHttpClientCodeGen()
|
||||
.getCode(requestModel, defaultUriScheme);
|
||||
.getCode(requestModel, defaultUriScheme, boundary);
|
||||
case CodegenLanguage.pythonRequests:
|
||||
return PythonRequestsCodeGen().getCode(requestModel, defaultUriScheme);
|
||||
return PythonRequestsCodeGen()
|
||||
.getCode(requestModel, defaultUriScheme, boundary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'package:jinja/jinja.dart' as jj;
|
||||
import 'package:apidash/utils/utils.dart'
|
||||
show getNewUuid, getValidRequestUri, padMultilineString;
|
||||
show getValidRequestUri, padMultilineString;
|
||||
import 'package:apidash/models/models.dart' show RequestModel;
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
@ -89,9 +89,8 @@ body = b'\r\n'.join(dataList)
|
||||
String? getCode(
|
||||
RequestModel requestModel,
|
||||
String defaultUriScheme,
|
||||
String? boundary,
|
||||
) {
|
||||
String uuid = getNewUuid();
|
||||
|
||||
try {
|
||||
String result = "";
|
||||
bool hasHeaders = false;
|
||||
@ -148,7 +147,7 @@ body = b'\r\n'.join(dataList)
|
||||
var formHeaderTemplate =
|
||||
jj.Template(kTemplateFormHeaderContentType);
|
||||
headers[HttpHeaders.contentTypeHeader] = formHeaderTemplate.render({
|
||||
"boundary": uuid,
|
||||
"boundary": boundary,
|
||||
});
|
||||
}
|
||||
|
||||
@ -169,7 +168,7 @@ body = b'\r\n'.join(dataList)
|
||||
result += formDataBodyData.render(
|
||||
{
|
||||
"fields_list": json.encode(requestModel.formDataMapList),
|
||||
"boundary": uuid,
|
||||
"boundary": boundary,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import 'dart:convert';
|
||||
import 'package:jinja/jinja.dart' as jj;
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/utils/utils.dart'
|
||||
show getNewUuid, getValidRequestUri, padMultilineString, stripUriParams;
|
||||
show getValidRequestUri, padMultilineString, stripUriParams;
|
||||
import 'package:apidash/models/models.dart' show RequestModel;
|
||||
|
||||
class PythonRequestsCodeGen {
|
||||
@ -94,6 +94,7 @@ print('Response Body:', response.text)
|
||||
String? getCode(
|
||||
RequestModel requestModel,
|
||||
String defaultUriScheme,
|
||||
String? boundary,
|
||||
) {
|
||||
try {
|
||||
String result = "";
|
||||
@ -101,7 +102,6 @@ print('Response Body:', response.text)
|
||||
bool hasHeaders = false;
|
||||
bool hasBody = false;
|
||||
bool hasJsonBody = false;
|
||||
String uuid = getNewUuid();
|
||||
|
||||
String url = requestModel.url;
|
||||
if (!url.contains("://") && url.isNotEmpty) {
|
||||
@ -155,7 +155,7 @@ print('Response Body:', response.text)
|
||||
var formHeaderTemplate =
|
||||
jj.Template(kTemplateFormHeaderContentType);
|
||||
headers[HttpHeaders.contentTypeHeader] = formHeaderTemplate.render({
|
||||
"boundary": uuid,
|
||||
"boundary": boundary,
|
||||
});
|
||||
}
|
||||
if (headers.isNotEmpty || hasBody) {
|
||||
@ -175,7 +175,7 @@ print('Response Body:', response.text)
|
||||
result += formDataBodyData.render(
|
||||
{
|
||||
"fields_list": json.encode(requestModel.formDataMapList),
|
||||
"boundary": uuid,
|
||||
"boundary": boundary,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user