-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
46 lines (34 loc) · 1.2 KB
/
test.c
File metadata and controls
46 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
int main(void) {
CURL *curl;
CURLcode res;
struct curl_slist *headers = NULL;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://your-go-server:8080");
// Set HTTP/2
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
// Set custom headers
headers = curl_slist_append(headers, "Upgrade: h2c");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// Set the CONNECT method
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "CONNECT");
// Set the proxy tunnel
curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
// Set the target host
curl_easy_setopt(curl, CURLOPT_PROXY, "target-host:target-port");
// Perform the request
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
// Clean up
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}