lib1514.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, 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.haxx.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. ***************************************************************************/
  22. /*
  23. * Make sure libcurl does not send a `Content-Length: -1` header when HTTP POST
  24. * size is unknown.
  25. */
  26. #include "test.h"
  27. #include "memdebug.h"
  28. static char data[]="dummy";
  29. struct WriteThis {
  30. char *readptr;
  31. size_t sizeleft;
  32. };
  33. static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
  34. {
  35. struct WriteThis *pooh = (struct WriteThis *)userp;
  36. if(size*nmemb < 1)
  37. return 0;
  38. if(pooh->sizeleft) {
  39. *(char *)ptr = pooh->readptr[0]; /* copy one single byte */
  40. pooh->readptr++; /* advance pointer */
  41. pooh->sizeleft--; /* less data left */
  42. return 1; /* we return 1 byte at a time! */
  43. }
  44. return 0; /* no more data left to deliver */
  45. }
  46. int test(char *URL)
  47. {
  48. CURL *curl;
  49. CURLcode result = CURLE_OK;
  50. int res = 0;
  51. struct WriteThis pooh = { data, sizeof(data)-1 };
  52. global_init(CURL_GLOBAL_ALL);
  53. easy_init(curl);
  54. easy_setopt(curl, CURLOPT_URL, URL);
  55. easy_setopt(curl, CURLOPT_POST, 1L);
  56. /* Purposely omit to set CURLOPT_POSTFIELDSIZE */
  57. easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  58. easy_setopt(curl, CURLOPT_READDATA, &pooh);
  59. #ifdef LIB1539
  60. /* speak HTTP 1.0 - no chunked! */
  61. easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  62. #endif
  63. result = curl_easy_perform(curl);
  64. test_cleanup:
  65. curl_easy_cleanup(curl);
  66. curl_global_cleanup();
  67. return (int)result;
  68. }