Annotation of embedaddon/curl/tests/libtest/lib1525.c, revision 1.1
1.1 ! misho 1: /***************************************************************************
! 2: * _ _ ____ _
! 3: * Project ___| | | | _ \| |
! 4: * / __| | | | |_) | |
! 5: * | (__| |_| | _ <| |___
! 6: * \___|\___/|_| \_\_____|
! 7: *
! 8: * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
! 9: * Copyright (C) 2014, Vijay Panghal, <vpanghal@maginatics.com>, et al.
! 10: *
! 11: * This software is licensed as described in the file COPYING, which
! 12: * you should have received as part of this distribution. The terms
! 13: * are also available at https://curl.haxx.se/docs/copyright.html.
! 14: *
! 15: * You may opt to use, copy, modify, merge, publish, distribute and/or sell
! 16: * copies of the Software, and permit persons to whom the Software is
! 17: * furnished to do so, under the terms of the COPYING file.
! 18: *
! 19: * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
! 20: * KIND, either express or implied.
! 21: *
! 22: ***************************************************************************/
! 23:
! 24: /*
! 25: * This unit test PUT http data over proxy. Proxy header will be different
! 26: * from server http header
! 27: */
! 28:
! 29: #include "test.h"
! 30:
! 31: #include "memdebug.h"
! 32:
! 33: static char data [] = "Hello Cloud!\n";
! 34:
! 35: static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
! 36: {
! 37: size_t amount = nmemb * size; /* Total bytes curl wants */
! 38: if(amount < strlen(data)) {
! 39: return strlen(data);
! 40: }
! 41: (void)stream;
! 42: memcpy(ptr, data, strlen(data));
! 43: return strlen(data);
! 44: }
! 45:
! 46:
! 47: int test(char *URL)
! 48: {
! 49: CURL *curl = NULL;
! 50: CURLcode res = CURLE_FAILED_INIT;
! 51: /* http and proxy header list*/
! 52: struct curl_slist *hhl = NULL;
! 53:
! 54: if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
! 55: fprintf(stderr, "curl_global_init() failed\n");
! 56: return TEST_ERR_MAJOR_BAD;
! 57: }
! 58:
! 59: curl = curl_easy_init();
! 60: if(!curl) {
! 61: fprintf(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:
! 68: if(!hhl) {
! 69: goto test_cleanup;
! 70: }
! 71:
! 72: test_setopt(curl, CURLOPT_URL, URL);
! 73: test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
! 74: test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
! 75: test_setopt(curl, CURLOPT_PROXYHEADER, hhl);
! 76: test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
! 77: test_setopt(curl, CURLOPT_POST, 0L);
! 78: test_setopt(curl, CURLOPT_UPLOAD, 1L);
! 79: test_setopt(curl, CURLOPT_VERBOSE, 1L);
! 80: test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
! 81: test_setopt(curl, CURLOPT_HEADER, 1L);
! 82: test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
! 83: test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
! 84: test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
! 85: test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(data));
! 86:
! 87: res = curl_easy_perform(curl);
! 88:
! 89: test_cleanup:
! 90:
! 91: curl_easy_cleanup(curl);
! 92:
! 93: curl_slist_free_all(hhl);
! 94:
! 95: curl_global_cleanup();
! 96:
! 97: return (int)res;
! 98: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>