verified header only mode

This commit is contained in:
Fufu Fang 2018-07-19 10:19:47 +01:00
parent af5b5e9486
commit 86e62ebb52
2 changed files with 23 additions and 7 deletions

2
http.c
View File

@ -286,6 +286,8 @@ URL_FILE *url_fopen(const char *url, const char *operation)
CURLOPT_HEADERDATA, file);
curl_easy_setopt(file->handle,
CURLOPT_HEADERFUNCTION, header_callback);
curl_easy_setopt(file->handle,
CURLOPT_NOBODY, 1L);
break;
default:
fprintf(stderr, "url_fopen: invalid operation %c", *c);

28
test.c
View File

@ -18,11 +18,31 @@ int http_test()
const char *url;
url = "http://127.0.0.1/~fangfufu/test.txt";
// url = "https://www.fangfufu.co.uk/~fangfufu/Unison-Windows-2.48.4.zip";
/* ------------------------Test header-only--------------------------*/
/* open the input file */
handle = url_fopen(url, "h");
if(!handle) {
printf("couldn't url_fopen() %s\n", url);
return 2;
}
/* Read 2 character seem to be enough to get the header*/
url_fgets(buffer, 2, handle);
/* Print the header */
printf(handle->header);
printf("\n");
printf("accept-range: %d\n", handle->accept_range);
printf("filesize: %d\n", handle->content_length);
/* close the URL handle */
url_fclose(handle);
/* ---------------------------Test fgets ----------------------------*/
/* open the input file */
handle = url_fopen(url, "hr");
handle = url_fopen(url, "h");
if(!handle) {
printf("couldn't url_fopen() %s\n", url);
return 2;
@ -41,12 +61,6 @@ int http_test()
fwrite(buffer, 1, strlen(buffer), outf);
}
/* Print the header */
printf(handle->header);
printf("\n");
printf("accept-range: %d\n", handle->accept_range);
printf("filesize: %d\n", handle->content_length);
/* close the handles for the fgets test*/
url_fclose(handle);
fclose(outf);