quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

lib1527.c (3086B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Vijay Panghal, <vpanghal@maginatics.com>, 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 /*
     26  * This unit test PUT http data over proxy. Same  http header will be generated
     27  * for server and proxy
     28  */
     29 
     30 #include "first.h"
     31 
     32 #include "memdebug.h"
     33 
     34 static const char t1527_testdata[] = "Hello Cloud!\n";
     35 
     36 static size_t t1527_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
     37 {
     38   size_t  amount = nmemb * size; /* Total bytes curl wants */
     39   if(amount < strlen(t1527_testdata)) {
     40     return strlen(t1527_testdata);
     41   }
     42   (void)stream;
     43   memcpy(ptr, t1527_testdata, strlen(t1527_testdata));
     44   return strlen(t1527_testdata);
     45 }
     46 
     47 static CURLcode test_lib1527(char *URL)
     48 {
     49   CURL *curl = NULL;
     50   CURLcode res = CURLE_FAILED_INIT;
     51   /* http header list */
     52   struct curl_slist *hhl = NULL, *tmp = NULL;
     53 
     54   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     55     curl_mfprintf(stderr, "curl_global_init() failed\n");
     56     return TEST_ERR_MAJOR_BAD;
     57   }
     58 
     59   curl = curl_easy_init();
     60   if(!curl) {
     61     curl_mfprintf(stderr, "curl_easy_init() failed\n");
     62     curl_global_cleanup();
     63     return TEST_ERR_MAJOR_BAD;
     64   }
     65 
     66   hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
     67   if(!hhl) {
     68     goto test_cleanup;
     69   }
     70   tmp = curl_slist_append(hhl, "Expect: 100-continue");
     71   if(!tmp) {
     72     goto test_cleanup;
     73   }
     74   hhl = tmp;
     75 
     76   test_setopt(curl, CURLOPT_URL, URL);
     77   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
     78   test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
     79   test_setopt(curl, CURLOPT_POST, 0L);
     80   test_setopt(curl, CURLOPT_UPLOAD, 1L);
     81   test_setopt(curl, CURLOPT_VERBOSE, 1L);
     82   test_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP);
     83   test_setopt(curl, CURLOPT_HEADER, 1L);
     84   test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
     85   test_setopt(curl, CURLOPT_READFUNCTION, t1527_read_cb);
     86   test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
     87   test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(t1527_testdata));
     88   test_setopt(curl, CURLOPT_HEADEROPT, (long)CURLHEADER_UNIFIED);
     89 
     90   res = curl_easy_perform(curl);
     91 
     92 test_cleanup:
     93 
     94   curl_easy_cleanup(curl);
     95 
     96   curl_slist_free_all(hhl);
     97 
     98   curl_global_cleanup();
     99 
    100   return res;
    101 }