2
0

lib1598.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. /*
  25. * This unit test PUT http data over proxy. Proxy header will be different
  26. * from server http header
  27. */
  28. #include "test.h"
  29. #include <stdio.h>
  30. #include "memdebug.h"
  31. /*
  32. * carefully not leak memory on OOM
  33. */
  34. static int trailers_callback(struct curl_slist **list, void *userdata)
  35. {
  36. struct curl_slist *nlist = NULL;
  37. struct curl_slist *nlist2 = NULL;
  38. (void)userdata;
  39. nlist = curl_slist_append(*list, "my-super-awesome-trailer: trail1");
  40. if(nlist)
  41. nlist2 = curl_slist_append(nlist, "my-other-awesome-trailer: trail2");
  42. if(nlist2) {
  43. *list = nlist2;
  44. return CURL_TRAILERFUNC_OK;
  45. }
  46. else {
  47. curl_slist_free_all(nlist);
  48. return CURL_TRAILERFUNC_ABORT;
  49. }
  50. }
  51. static const char *post_data = "xxx=yyy&aaa=bbbbb";
  52. CURLcode test(char *URL)
  53. {
  54. CURL *curl = NULL;
  55. CURLcode res = CURLE_FAILED_INIT;
  56. /* http and proxy header list */
  57. struct curl_slist *hhl = NULL, *list;
  58. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  59. fprintf(stderr, "curl_global_init() failed\n");
  60. return TEST_ERR_MAJOR_BAD;
  61. }
  62. curl = curl_easy_init();
  63. if(!curl) {
  64. fprintf(stderr, "curl_easy_init() failed\n");
  65. curl_global_cleanup();
  66. return TEST_ERR_MAJOR_BAD;
  67. }
  68. hhl = curl_slist_append(hhl, "Trailer: my-super-awesome-trailer,"
  69. " my-other-awesome-trailer");
  70. if(!hhl)
  71. goto test_cleanup;
  72. if(hhl) {
  73. list = curl_slist_append(hhl, "Transfer-Encoding: chunked");
  74. if(!list)
  75. goto test_cleanup;
  76. hhl = list;
  77. }
  78. test_setopt(curl, CURLOPT_URL, URL);
  79. test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
  80. test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(post_data));
  81. test_setopt(curl, CURLOPT_POSTFIELDS, post_data);
  82. test_setopt(curl, CURLOPT_TRAILERFUNCTION, trailers_callback);
  83. test_setopt(curl, CURLOPT_TRAILERDATA, NULL);
  84. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  85. res = curl_easy_perform(curl);
  86. test_cleanup:
  87. curl_easy_cleanup(curl);
  88. curl_slist_free_all(hhl);
  89. curl_global_cleanup();
  90. return res;
  91. }