Commit 1119729e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: fetch/store cookies in the cookie jar

If present - this is currently only supported by the playlist.

Header field folding is not implemented.
parent 6c76c9ba
......@@ -113,8 +113,6 @@ static int Open(vlc_object_t *obj)
if (var_InheritBool(obj, "http-continuous"))
return VLC_EGENERIC; /* FIXME not implemented yet */
if (var_InheritBool(obj, "http-forward-cookies"))
return VLC_EGENERIC; /* FIXME not implemented yet */
char *proxy = vlc_getProxyUrl(access->psz_url);
free(proxy);
......@@ -130,7 +128,13 @@ static int Open(vlc_object_t *obj)
sys->manager = NULL;
sys->file = NULL;
sys->manager = vlc_http_mgr_create(obj, var_InheritBool(obj, "http2"));
void *jar = NULL;
if (var_InheritBool(obj, "http-forward-cookies"))
jar = var_InheritAddress(obj, "http-cookies");
bool h2c = var_InheritBool(obj, "http2");
sys->manager = vlc_http_mgr_create(obj, jar, h2c);
if (sys->manager == NULL)
goto error;
......
......@@ -25,6 +25,7 @@
#include <assert.h>
#include <vlc_common.h>
#include <vlc_tls.h>
#include <vlc_http.h>
#include <vlc_interrupt.h>
#include "transport.h"
#include "conn.h"
......@@ -134,6 +135,7 @@ struct vlc_http_mgr
{
vlc_object_t *obj;
vlc_tls_creds_t *creds;
vlc_http_cookie_jar_t *jar;
struct vlc_http_conn *conn;
bool use_h2c;
};
......@@ -270,7 +272,40 @@ struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
return (https ? vlc_https_request : vlc_http_request)(mgr, host, port, m);
}
struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj, bool h2c)
int vlc_http_mgr_send_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
struct vlc_http_msg *req)
{
int ret = 0;
if (mgr->jar != NULL)
{
char *cookies = vlc_http_cookies_fetch(mgr->jar, https, host, path);
if (cookies != NULL)
{
msg_Dbg(mgr->obj, "retrieved cookies: %s", cookies);
ret = vlc_http_msg_add_header(req, "Cookie", "%s", cookies);
free(cookies);
}
}
return ret;
}
void vlc_http_mgr_recv_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
const struct vlc_http_msg *resp)
{
if (mgr->jar != NULL)
{ /* FIXME: fold multiple Set-Cookies headers with ';' */
const char *cookies = vlc_http_msg_get_header(resp, "Set-Cookie");
if (cookies != NULL
&& vlc_http_cookies_store(mgr->jar, cookies, https, host, path))
msg_Dbg(mgr->obj, "stored cookie: %s", cookies);
}
}
struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj,
vlc_http_cookie_jar_t *jar, bool h2c)
{
struct vlc_http_mgr *mgr = malloc(sizeof (*mgr));
if (unlikely(mgr == NULL))
......@@ -278,6 +313,7 @@ struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj, bool h2c)
mgr->obj = obj;
mgr->creds = NULL;
mgr->jar = jar;
mgr->conn = NULL;
mgr->use_h2c = h2c;
return mgr;
......
......@@ -20,10 +20,19 @@
struct vlc_http_mgr;
struct vlc_http_msg;
struct vlc_http_cookie_jar_t;
struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
const char *host, unsigned port,
const struct vlc_http_msg *req);
int vlc_http_mgr_send_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
struct vlc_http_msg *req);
void vlc_http_mgr_recv_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
const struct vlc_http_msg *resp);
struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj, bool try_h2c);
struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj,
struct vlc_http_cookie_jar_t *jar,
bool h2c);
void vlc_http_mgr_destroy(struct vlc_http_mgr *mgr);
......@@ -123,6 +123,9 @@ static struct vlc_http_msg *vlc_http_file_open(struct vlc_http_file *file,
if (unlikely(req == NULL))
return NULL;
vlc_http_mgr_send_cookies(file->manager, file->secure, file->host,
file->path, req);
struct vlc_http_msg *resp = vlc_http_mgr_request(file->manager,
file->secure, file->host, file->port, req);
vlc_http_msg_destroy(req);
......@@ -131,6 +134,9 @@ static struct vlc_http_msg *vlc_http_file_open(struct vlc_http_file *file,
if (resp == NULL)
return NULL;
vlc_http_mgr_recv_cookies(file->manager, file->secure, file->host,
file->path, resp);
int status = vlc_http_msg_get_status(resp);
if (status < 200 || status >= 599)
goto fail;
......
......@@ -284,3 +284,26 @@ struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
return vlc_http_stream_read_headers(&stream);
}
int vlc_http_mgr_send_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
struct vlc_http_msg *req)
{
assert(https);
assert(!strcmp(host, "www.example.com"));
assert(!strcmp(path, "/dir/file.ext?a=b"));
assert(mgr == NULL);
(void) req;
return 0;
}
void vlc_http_mgr_recv_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
const struct vlc_http_msg *resp)
{
assert(https);
assert(!strcmp(host, "www.example.com"));
assert(!strcmp(path, "/dir/file.ext?a=b"));
assert(mgr == NULL);
(void) resp;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment