Created
September 13, 2024 08:22
-
-
Save bagder/8c7270e857ff83a16aea13fe3aa2b496 to your computer and use it in GitHub Desktop.
Reproducing curl issue #14892
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <fcntl.h> | |
#include <sys/stat.h> | |
#include <errno.h> | |
/* curl stuff */ | |
#include <curl/curl.h> | |
#include <curl/mprintf.h> | |
struct input { | |
FILE *in; | |
size_t bytes_read; /* count up */ | |
CURL *hnd; | |
}; | |
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) | |
{ | |
struct input *i = userp; | |
size_t retcode = fread(ptr, size, nmemb, i->in); | |
i->bytes_read += retcode; | |
return retcode; | |
} | |
static void setup(struct input *i, const char *upload) | |
{ | |
FILE *out; | |
char url[256]; | |
char filename[128]; | |
CURL *hnd; | |
if(!i->hnd) | |
i->hnd = curl_easy_init(); | |
hnd = i->hnd; | |
i->in = fopen(upload, "rb"); | |
if(!i->in) { | |
fprintf(stderr, "error: could not open file %s for reading: %s\n", upload, | |
strerror(errno)); | |
exit(1); | |
} | |
/* we want to use our own read function */ | |
curl_easy_setopt(hnd, CURLOPT_READFUNCTION, read_callback); | |
/* read from this file */ | |
curl_easy_setopt(hnd, CURLOPT_READDATA, i); | |
/* send in the URL to store the upload as */ | |
curl_easy_setopt(hnd, CURLOPT_URL, "https://curl.se"); | |
/* upload please */ | |
curl_easy_setopt(hnd, CURLOPT_POST, 1L); | |
/* please be verbose */ | |
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); | |
/* HTTP/2 please */ | |
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); | |
} | |
/* | |
* Upload all files over HTTP/2, using the same physical connection! | |
*/ | |
struct input trans; | |
int main(int argc, char **argv) | |
{ | |
const char *filename = "5K"; | |
setup(&trans, filename); | |
curl_easy_perform(trans.hnd); | |
fclose(trans.in); | |
setup(&trans, filename); | |
curl_easy_perform(trans.hnd); | |
fclose(trans.in); | |
curl_easy_cleanup(trans.hnd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment