mirror of
https://github.com/moparisthebest/curl
synced 2025-01-11 05:58:01 -05:00
altsvc: clone setting in curl_easy_duphandle
The cache content is not duplicated, like other caches, but the setting and specified file name are. Test 1908 is extended to verify this somewhat. Since the duplicated handle gets the same file name, the test unfortunately overwrites the same file twice (with different contents) which makes it hard to check automatically. Closes #5923
This commit is contained in:
parent
8ca54a03ea
commit
f93455eb04
@ -302,11 +302,12 @@ CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl)
|
|||||||
* Curl_altsvc_cleanup() frees an altsvc cache instance and all associated
|
* Curl_altsvc_cleanup() frees an altsvc cache instance and all associated
|
||||||
* resources.
|
* resources.
|
||||||
*/
|
*/
|
||||||
void Curl_altsvc_cleanup(struct altsvcinfo *altsvc)
|
void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp)
|
||||||
{
|
{
|
||||||
struct Curl_llist_element *e;
|
struct Curl_llist_element *e;
|
||||||
struct Curl_llist_element *n;
|
struct Curl_llist_element *n;
|
||||||
if(altsvc) {
|
if(*altsvcp) {
|
||||||
|
struct altsvcinfo *altsvc = *altsvcp;
|
||||||
for(e = altsvc->list.head; e; e = n) {
|
for(e = altsvc->list.head; e; e = n) {
|
||||||
struct altsvc *as = e->ptr;
|
struct altsvc *as = e->ptr;
|
||||||
n = e->next;
|
n = e->next;
|
||||||
@ -314,6 +315,7 @@ void Curl_altsvc_cleanup(struct altsvcinfo *altsvc)
|
|||||||
}
|
}
|
||||||
free(altsvc->filename);
|
free(altsvc->filename);
|
||||||
free(altsvc);
|
free(altsvc);
|
||||||
|
*altsvcp = NULL; /* clear the pointer */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file);
|
|||||||
CURLcode Curl_altsvc_save(struct Curl_easy *data,
|
CURLcode Curl_altsvc_save(struct Curl_easy *data,
|
||||||
struct altsvcinfo *asi, const char *file);
|
struct altsvcinfo *asi, const char *file);
|
||||||
CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl);
|
CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl);
|
||||||
void Curl_altsvc_cleanup(struct altsvcinfo *altsvc);
|
void Curl_altsvc_cleanup(struct altsvcinfo **altsvc);
|
||||||
CURLcode Curl_altsvc_parse(struct Curl_easy *data,
|
CURLcode Curl_altsvc_parse(struct Curl_easy *data,
|
||||||
struct altsvcinfo *altsvc, const char *value,
|
struct altsvcinfo *altsvc, const char *value,
|
||||||
enum alpnid srcalpn, const char *srchost,
|
enum alpnid srcalpn, const char *srchost,
|
||||||
@ -74,5 +74,6 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi,
|
|||||||
#else
|
#else
|
||||||
/* disabled */
|
/* disabled */
|
||||||
#define Curl_altsvc_save(a,b,c)
|
#define Curl_altsvc_save(a,b,c)
|
||||||
|
#define Curl_altsvc_cleanup(x)
|
||||||
#endif /* CURL_DISABLE_HTTP || USE_ALTSVC */
|
#endif /* CURL_DISABLE_HTTP || USE_ALTSVC */
|
||||||
#endif /* HEADER_CURL_ALTSVC_H */
|
#endif /* HEADER_CURL_ALTSVC_H */
|
||||||
|
11
lib/easy.c
11
lib/easy.c
@ -78,6 +78,7 @@
|
|||||||
#include "system_win32.h"
|
#include "system_win32.h"
|
||||||
#include "http2.h"
|
#include "http2.h"
|
||||||
#include "dynbuf.h"
|
#include "dynbuf.h"
|
||||||
|
#include "altsvc.h"
|
||||||
|
|
||||||
/* The last 3 #include files should be in this order */
|
/* The last 3 #include files should be in this order */
|
||||||
#include "curl_printf.h"
|
#include "curl_printf.h"
|
||||||
@ -883,6 +884,15 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_ALTSVC
|
||||||
|
if(data->asi) {
|
||||||
|
outcurl->asi = Curl_altsvc_init();
|
||||||
|
if(!outcurl->asi)
|
||||||
|
goto fail;
|
||||||
|
if(outcurl->set.str[STRING_ALTSVC])
|
||||||
|
(void)Curl_altsvc_load(outcurl->asi, outcurl->set.str[STRING_ALTSVC]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
/* Clone the resolver handle, if present, for the new handle */
|
/* Clone the resolver handle, if present, for the new handle */
|
||||||
if(Curl_resolver_duphandle(outcurl,
|
if(Curl_resolver_duphandle(outcurl,
|
||||||
&outcurl->state.resolver,
|
&outcurl->state.resolver,
|
||||||
@ -930,6 +940,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
|
|||||||
Curl_dyn_free(&outcurl->state.headerb);
|
Curl_dyn_free(&outcurl->state.headerb);
|
||||||
Curl_safefree(outcurl->change.url);
|
Curl_safefree(outcurl->change.url);
|
||||||
Curl_safefree(outcurl->change.referer);
|
Curl_safefree(outcurl->change.referer);
|
||||||
|
Curl_altsvc_cleanup(&outcurl->asi);
|
||||||
Curl_freeset(outcurl);
|
Curl_freeset(outcurl);
|
||||||
free(outcurl);
|
free(outcurl);
|
||||||
}
|
}
|
||||||
|
@ -391,11 +391,8 @@ CURLcode Curl_close(struct Curl_easy **datap)
|
|||||||
Curl_dyn_free(&data->state.headerb);
|
Curl_dyn_free(&data->state.headerb);
|
||||||
Curl_safefree(data->state.ulbuf);
|
Curl_safefree(data->state.ulbuf);
|
||||||
Curl_flush_cookies(data, TRUE);
|
Curl_flush_cookies(data, TRUE);
|
||||||
#ifdef USE_ALTSVC
|
|
||||||
Curl_altsvc_save(data, data->asi, data->set.str[STRING_ALTSVC]);
|
Curl_altsvc_save(data, data->asi, data->set.str[STRING_ALTSVC]);
|
||||||
Curl_altsvc_cleanup(data->asi);
|
Curl_altsvc_cleanup(&data->asi);
|
||||||
data->asi = NULL;
|
|
||||||
#endif
|
|
||||||
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
|
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
|
||||||
Curl_http_auth_cleanup_digest(data);
|
Curl_http_auth_cleanup_digest(data);
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,7 +8,7 @@ CURLINFO_EFFECTIVE_URL
|
|||||||
# Server-side
|
# Server-side
|
||||||
<reply>
|
<reply>
|
||||||
<data nocheck="yes">
|
<data nocheck="yes">
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK swsbounce
|
||||||
Date: Thu, 09 Nov 2010 14:49:00 GMT
|
Date: Thu, 09 Nov 2010 14:49:00 GMT
|
||||||
Server: test-server/fake
|
Server: test-server/fake
|
||||||
Content-Type: text/html
|
Content-Type: text/html
|
||||||
@ -17,6 +17,15 @@ Content-Length: 0
|
|||||||
alt-svc: h2="3dbbdetxoyw4nsp6c3cc456oj2ays6s43ezxzsfxxri3h5xqd.example:443"; ma=315360000; persist=1
|
alt-svc: h2="3dbbdetxoyw4nsp6c3cc456oj2ays6s43ezxzsfxxri3h5xqd.example:443"; ma=315360000; persist=1
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
# This is the second response
|
||||||
|
<data1 nocheck="yes">
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
Connection: close
|
||||||
|
Content-Length: 0
|
||||||
|
alt-svc: h2="second.example:443"; ma=315360000;
|
||||||
|
|
||||||
|
</data1>
|
||||||
</reply>
|
</reply>
|
||||||
|
|
||||||
# Client-side
|
# Client-side
|
||||||
@ -56,6 +65,10 @@ GET /1908 HTTP/1.1
|
|||||||
Host: %HOSTIP:%HTTPPORT
|
Host: %HOSTIP:%HTTPPORT
|
||||||
Accept: */*
|
Accept: */*
|
||||||
|
|
||||||
|
GET /1908 HTTP/1.1
|
||||||
|
Host: %HOSTIP:%HTTPPORT
|
||||||
|
Accept: */*
|
||||||
|
|
||||||
</protocol>
|
</protocol>
|
||||||
<stripfile>
|
<stripfile>
|
||||||
# strip out the (dynamic) expire date from the file so that the rest
|
# strip out the (dynamic) expire date from the file so that the rest
|
||||||
|
@ -39,7 +39,22 @@ int test(char *URL)
|
|||||||
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
|
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
|
||||||
curl_easy_setopt(hnd, CURLOPT_ALTSVC, "log/altsvc-1908");
|
curl_easy_setopt(hnd, CURLOPT_ALTSVC, "log/altsvc-1908");
|
||||||
ret = curl_easy_perform(hnd);
|
ret = curl_easy_perform(hnd);
|
||||||
|
|
||||||
|
if(!ret) {
|
||||||
|
/* make a copy and check that this also has alt-svc activated */
|
||||||
|
CURL *also = curl_easy_duphandle(hnd);
|
||||||
|
if(also) {
|
||||||
|
ret = curl_easy_perform(also);
|
||||||
|
/* we close the second handle first, which makes it store the alt-svc
|
||||||
|
file only to get overwritten when the next handle is closed! */
|
||||||
|
curl_easy_cleanup(also);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
curl_easy_reset(hnd);
|
curl_easy_reset(hnd);
|
||||||
|
|
||||||
|
/* using the same file name for the alt-svc cache, this clobbers the
|
||||||
|
content just written from the 'also' handle */
|
||||||
curl_easy_cleanup(hnd);
|
curl_easy_cleanup(hnd);
|
||||||
}
|
}
|
||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
|
@ -54,7 +54,7 @@ UNITTEST_START
|
|||||||
return 1;
|
return 1;
|
||||||
result = Curl_altsvc_load(asi, arg);
|
result = Curl_altsvc_load(asi, arg);
|
||||||
if(result) {
|
if(result) {
|
||||||
Curl_altsvc_cleanup(asi);
|
Curl_altsvc_cleanup(&asi);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
@ -131,7 +131,7 @@ UNITTEST_START
|
|||||||
|
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
fail:
|
fail:
|
||||||
Curl_altsvc_cleanup(asi);
|
Curl_altsvc_cleanup(&asi);
|
||||||
return unitfail;
|
return unitfail;
|
||||||
}
|
}
|
||||||
UNITTEST_STOP
|
UNITTEST_STOP
|
||||||
|
Loading…
Reference in New Issue
Block a user