Skip to content

Commit dd55683

Browse files
committed
better curlConfig handling on c-libcurl
1 parent f7f108f commit dd55683

4 files changed

Lines changed: 36 additions & 28 deletions

File tree

modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,6 @@ void apiClient_invoke(apiClient_t *apiClient,
503503
operationParameter,
504504
queryParameters);
505505

506-
if(apiClient->curlConfig->keepalive == 1) {
507-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L);
508-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle);
509-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl);
510-
}
511-
512506
curl_easy_setopt(handle, CURLOPT_URL, targetUrl);
513507
curl_easy_setopt(handle,
514508
CURLOPT_WRITEFUNCTION,
@@ -517,7 +511,6 @@ void apiClient_invoke(apiClient_t *apiClient,
517511
CURLOPT_WRITEDATA,
518512
apiClient);
519513
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
520-
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
521514

522515
{{#hasAuthMethods}}
523516
{{#authMethods}}
@@ -562,6 +555,15 @@ void apiClient_invoke(apiClient_t *apiClient,
562555
postData(handle, bodyParameters, bodyParametersLength);
563556
}
564557

558+
if(apiClient->curlConfig != NULL) {
559+
if(apiClient->curlConfig->keepalive == 1) {
560+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L);
561+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle);
562+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl);
563+
}
564+
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
565+
}
566+
565567
res = curl_easy_perform(handle);
566568

567569
curl_slist_free_all(headers);

samples/client/others/c/bearerAuth/src/apiClient.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,6 @@ void apiClient_invoke(apiClient_t *apiClient,
396396
operationParameter,
397397
queryParameters);
398398

399-
if(apiClient->curlConfig->keepalive == 1) {
400-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L);
401-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle);
402-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl);
403-
}
404-
405399
curl_easy_setopt(handle, CURLOPT_URL, targetUrl);
406400
curl_easy_setopt(handle,
407401
CURLOPT_WRITEFUNCTION,
@@ -410,13 +404,21 @@ void apiClient_invoke(apiClient_t *apiClient,
410404
CURLOPT_WRITEDATA,
411405
apiClient);
412406
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
413-
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
414407

415408

416409
if(bodyParameters != NULL) {
417410
postData(handle, bodyParameters, bodyParametersLength);
418411
}
419412

413+
if(apiClient->curlConfig != NULL) {
414+
if(apiClient->curlConfig->keepalive == 1) {
415+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L);
416+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle);
417+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl);
418+
}
419+
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
420+
}
421+
420422
res = curl_easy_perform(handle);
421423

422424
curl_slist_free_all(headers);

samples/client/petstore/c-useJsonUnformatted/src/apiClient.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,6 @@ void apiClient_invoke(apiClient_t *apiClient,
426426
operationParameter,
427427
queryParameters);
428428

429-
if(apiClient->curlConfig->keepalive == 1) {
430-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L);
431-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle);
432-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl);
433-
}
434-
435429
curl_easy_setopt(handle, CURLOPT_URL, targetUrl);
436430
curl_easy_setopt(handle,
437431
CURLOPT_WRITEFUNCTION,
@@ -440,7 +434,6 @@ void apiClient_invoke(apiClient_t *apiClient,
440434
CURLOPT_WRITEDATA,
441435
apiClient);
442436
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
443-
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
444437

445438
// this would only be generated for OAuth2 authentication
446439
if(apiClient->accessToken != NULL) {
@@ -454,6 +447,15 @@ void apiClient_invoke(apiClient_t *apiClient,
454447
postData(handle, bodyParameters, bodyParametersLength);
455448
}
456449

450+
if(apiClient->curlConfig != NULL) {
451+
if(apiClient->curlConfig->keepalive == 1) {
452+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L);
453+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle);
454+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl);
455+
}
456+
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
457+
}
458+
457459
res = curl_easy_perform(handle);
458460

459461
curl_slist_free_all(headers);

samples/client/petstore/c/src/apiClient.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,6 @@ void apiClient_invoke(apiClient_t *apiClient,
426426
operationParameter,
427427
queryParameters);
428428

429-
if(apiClient->curlConfig->keepalive == 1) {
430-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L);
431-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle);
432-
curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl);
433-
}
434-
435429
curl_easy_setopt(handle, CURLOPT_URL, targetUrl);
436430
curl_easy_setopt(handle,
437431
CURLOPT_WRITEFUNCTION,
@@ -440,7 +434,6 @@ void apiClient_invoke(apiClient_t *apiClient,
440434
CURLOPT_WRITEDATA,
441435
apiClient);
442436
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
443-
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
444437

445438
// this would only be generated for OAuth2 authentication
446439
if(apiClient->accessToken != NULL) {
@@ -454,6 +447,15 @@ void apiClient_invoke(apiClient_t *apiClient,
454447
postData(handle, bodyParameters, bodyParametersLength);
455448
}
456449

450+
if(apiClient->curlConfig != NULL) {
451+
if(apiClient->curlConfig->keepalive == 1) {
452+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPALIVE, 1L);
453+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPIDLE, apiClient->curlConfig->keepidle);
454+
curl_easy_setopt(handle, CURLOPT_TCP_KEEPINTVL, apiClient->curlConfig->keepintvl);
455+
}
456+
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
457+
}
458+
457459
res = curl_easy_perform(handle);
458460

459461
curl_slist_free_all(headers);

0 commit comments

Comments
 (0)