lib1901.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "test.h"
  25. #include "testutil.h"
  26. #include "warnless.h"
  27. #include "memdebug.h"
  28. static const char *chunks[]={
  29. "one",
  30. "two",
  31. "three",
  32. "four",
  33. NULL
  34. };
  35. static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
  36. {
  37. static int ix = 0;
  38. (void)size;
  39. (void)nmemb;
  40. (void)stream;
  41. if(chunks[ix]) {
  42. size_t len = strlen(chunks[ix]);
  43. strcpy(ptr, chunks[ix]);
  44. ix++;
  45. return len;
  46. }
  47. return 0;
  48. }
  49. CURLcode test(char *URL)
  50. {
  51. CURL *curl;
  52. CURLcode res = CURLE_OK;
  53. struct curl_slist *chunk = NULL;
  54. curl_global_init(CURL_GLOBAL_ALL);
  55. curl = curl_easy_init();
  56. if(curl) {
  57. /* deliberately setting the size - to a wrong value to make sure libcurl
  58. ignores it */
  59. easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 4L);
  60. easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
  61. easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  62. easy_setopt(curl, CURLOPT_POST, 1L);
  63. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  64. easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_1_1);
  65. easy_setopt(curl, CURLOPT_URL, URL);
  66. easy_setopt(curl, CURLOPT_READDATA, NULL);
  67. chunk = curl_slist_append(chunk, "Expect:");
  68. if(chunk) {
  69. struct curl_slist *n =
  70. curl_slist_append(chunk, "Transfer-Encoding: chunked");
  71. if(n)
  72. chunk = n;
  73. if(n)
  74. easy_setopt(curl, CURLOPT_HTTPHEADER, n);
  75. }
  76. res = curl_easy_perform(curl);
  77. }
  78. test_cleanup:
  79. curl_easy_cleanup(curl);
  80. curl_slist_free_all(chunk);
  81. curl_global_cleanup();
  82. return res;
  83. }