removed the unncessary header usage

This commit is contained in:
Nishant Kumar
2024-03-21 21:34:44 +05:30
parent 2a79270c4a
commit 816eae4b33
2 changed files with 122 additions and 139 deletions

View File

@ -24,7 +24,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "{{url}}");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
""";
String kTemplateBody = """
@ -36,6 +35,7 @@ int main() {
""";
String kTemplateFormData = """
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
@ -52,19 +52,14 @@ int main() {
""";
String kTemplateHeader = """
struct curl_slist *headers = NULL;
{% if headers %}{% for header, value in headers %}
headers = curl_slist_append(headers,"{{header}}: {{value}}");{% endfor %}
{% endif %}
""";
String kTemplateHeaderEnd = """
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
""";
String kStringFormDataHeader = """""";
String kTemplateQueryParam = """
""";
String kTemplateQueryParam = """""";
String kTemplateRequest = """
@ -117,8 +112,11 @@ int main() {
);
var headersList = requestModel.enabledRequestHeaders;
if (headersList != null || requestModel.hasBody) {
if (headersList != null || requestModel.hasBody || requestModel.hasFormData) {
var headers = requestModel.enabledHeadersMap;
if(requestModel.hasFormData){
headers.putIfAbsent("Content-Type", () => "multipart/form-data");
}
if (requestModel.hasJsonData || requestModel.hasTextData) {
headers.putIfAbsent(kHeaderContentType,
() => requestModel.requestBodyContentType.header);
@ -130,7 +128,6 @@ int main() {
});
}
}
result += kTemplateHeaderEnd;
Uri? uri = rec.$1;
@ -161,7 +158,7 @@ int main() {
var headers = requestModel.enabledHeadersMap;
bool allow = headers.isNotEmpty ||
requestModel.hasJsonData ||
requestModel.hasTextData;
requestModel.hasTextData || requestModel.hasFormData;
var templateEnd = jj.Template(kTemplateEnd);
result += templateEnd.render({
"formdata": requestModel.hasFormData,

View File

@ -23,9 +23,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -56,9 +53,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/country/data?code=US");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -89,9 +83,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/country/data?code=IND");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -122,9 +113,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -156,11 +144,11 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
@ -191,11 +179,11 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
@ -225,9 +213,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -259,11 +244,11 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
@ -293,9 +278,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social?num=8700000&add_space=true");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -327,11 +309,11 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
@ -365,11 +347,11 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
@ -399,9 +381,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -434,9 +413,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -467,9 +443,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "http://api.apidash.dev");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -503,10 +476,10 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: text/plain");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"text\": \"I LOVE Flutter\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
@ -542,10 +515,10 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"text\": \"I LOVE Flutter\",\n\"flag\": null,\n\"male\": true,\n\"female\": false,\n\"no\": 1.2,\n\"arr\": [\"null\", \"true\", \"false\", null]\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
@ -581,11 +554,11 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"text\": \"I LOVE Flutter\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
@ -621,6 +594,9 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
@ -644,7 +620,7 @@ int main() {
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
return 0;
@ -672,7 +648,9 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
@ -725,6 +703,9 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
@ -743,7 +724,7 @@ int main() {
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
return 0;
@ -771,6 +752,9 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
@ -789,7 +773,7 @@ int main() {
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
return 0;
@ -817,6 +801,9 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
@ -840,7 +827,7 @@ int main() {
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
return 0;
@ -868,8 +855,10 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
headers = curl_slist_append(headers,"Keep-Alive: true");
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
@ -919,10 +908,10 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
@ -960,10 +949,10 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
@ -1000,9 +989,6 @@ int main() {
curl_easy_setopt(curl, CURLOPT_URL, "https://reqres.in/api/users/2");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
@ -1034,10 +1020,10 @@ int main() {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);