lib1514.c 2.4 KB

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