Commit 4adb5fc7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

http: add parameter for proxied requests

parent 90c07084
......@@ -47,7 +47,7 @@ static inline void vlc_http_conn_release(struct vlc_http_conn *conn)
conn->cbs->release(conn);
}
struct vlc_http_conn *vlc_h1_conn_create(struct vlc_tls *);
struct vlc_http_conn *vlc_h1_conn_create(struct vlc_tls *, bool proxy);
struct vlc_http_conn *vlc_h2_conn_create(struct vlc_tls *);
struct vlc_http_stream *vlc_chunked_open(struct vlc_http_stream *,
......
......@@ -246,7 +246,7 @@ static struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
if (http2)
conn = vlc_h2_conn_create(tls);
else
conn = vlc_h1_conn_create(tls);
conn = vlc_h1_conn_create(tls, false);
if (unlikely(conn == NULL))
{
......@@ -279,7 +279,7 @@ static struct vlc_http_msg *vlc_http_request(struct vlc_http_mgr *mgr,
if (mgr->use_h2c)
conn = vlc_h2_conn_create(tls);
else
conn = vlc_h1_conn_create(tls);
conn = vlc_h1_conn_create(tls, false);
if (unlikely(conn == NULL))
{
......
......@@ -114,6 +114,7 @@ struct vlc_h1_conn
bool connection_close;
bool active;
bool released;
bool proxy;
};
#define CO(conn) ((conn)->conn.tls->obj)
......@@ -149,7 +150,7 @@ static struct vlc_http_stream *vlc_h1_stream_open(struct vlc_http_conn *c,
if (conn->active || conn->conn.tls == NULL)
return NULL;
char *payload = vlc_http_msg_format(req, &len);
char *payload = vlc_http_msg_format(req, &len, conn->proxy);
if (unlikely(payload == NULL))
return NULL;
......@@ -312,7 +313,7 @@ static const struct vlc_http_conn_cbs vlc_h1_conn_callbacks =
vlc_h1_conn_release,
};
struct vlc_http_conn *vlc_h1_conn_create(vlc_tls_t *tls)
struct vlc_http_conn *vlc_h1_conn_create(vlc_tls_t *tls, bool proxy)
{
struct vlc_h1_conn *conn = malloc(sizeof (*conn));
if (unlikely(conn == NULL))
......@@ -323,6 +324,7 @@ struct vlc_http_conn *vlc_h1_conn_create(vlc_tls_t *tls)
conn->stream.cbs = &vlc_h1_stream_callbacks;
conn->active = false;
conn->released = false;
conn->proxy = proxy;
return &conn->conn;
}
......@@ -55,7 +55,7 @@ static void conn_create(void)
external_fd = fds[0];
conn = vlc_h1_conn_create(tls);
conn = vlc_h1_conn_create(tls, false);
assert(conn != NULL);
}
......
......@@ -287,7 +287,8 @@ block_t *vlc_http_msg_read(struct vlc_http_msg *m)
/* Serialization and deserialization */
char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp)
char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp,
bool proxied)
{
size_t len;
......@@ -297,6 +298,12 @@ char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp)
len += strlen(m->method);
len += strlen(m->path ? m->path : m->authority);
len += strlen(m->authority);
if (proxied)
{
assert(m->scheme != NULL && m->path != NULL);
len += strlen(m->scheme) + 3 + strlen(m->authority);
}
}
else
len = sizeof ("HTTP/1.1 123 .\r\n\r\n");
......@@ -311,8 +318,13 @@ char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp)
len = 0;
if (m->status < 0)
len += sprintf(buf, "%s %s HTTP/1.1\r\nHost: %s\r\n", m->method,
{
len += sprintf(buf, "%s ", m->method);
if (proxied)
len += sprintf(buf + len, "%s://%s", m->scheme, m->authority);
len += sprintf(buf + len, "%s HTTP/1.1\r\nHost: %s\r\n",
m->path ? m->path : m->authority, m->authority);
}
else
len += sprintf(buf, "HTTP/1.1 %03hd .\r\n", m->status);
......
......@@ -252,7 +252,8 @@ static inline void vlc_http_stream_close(struct vlc_http_stream *s, bool abort)
s->cbs->close(s, abort);
}
char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *) VLC_USED;
char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp,
bool proxied) VLC_USED;
struct vlc_http_msg *vlc_http_msg_headers(const char *msg) VLC_USED;
struct vlc_h2_frame;
......
......@@ -115,7 +115,7 @@ static void check_msg(struct vlc_http_msg *in,
cb(in);
m1 = vlc_http_msg_format(in, &len);
m1 = vlc_http_msg_format(in, &len, false);
assert(m1 != NULL);
assert(strlen(m1) == len);
out = vlc_http_msg_headers(m1);
......
......@@ -140,8 +140,8 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
if (session == NULL)
return NULL;
struct vlc_http_conn *conn = (ptwo ? vlc_h2_conn_create
: vlc_h1_conn_create)(session);
struct vlc_http_conn *conn = ptwo ? vlc_h2_conn_create(session)
: vlc_h1_conn_create(session, false);
if (unlikely(conn == NULL))
{
vlc_tls_Close(session);
......
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