static void stream_reply(uint_fast32_t id, bool nodata) { struct vlc_http_msg *m = vlc_http_resp_create(200); assert(m != NULL); vlc_http_msg_add_agent(m, "VLC-h2-tester"); conn_send(vlc_http_msg_h2_frame(m, id, nodata)); vlc_http_msg_destroy(m); }
static struct vlc_http_msg * vlc_http_res_req(const struct vlc_http_resource *res, void *opaque) { struct vlc_http_msg *req; req = vlc_http_req_create("GET", res->secure ? "https" : "http", res->authority, res->path); if (unlikely(req == NULL)) return NULL; /* Content negotiation */ vlc_http_msg_add_header(req, "Accept", "*/*"); if (res->negotiate) { const char *lang = vlc_gettext("C"); if (!strcmp(lang, "C")) lang = "en_US"; vlc_http_msg_add_header(req, "Accept-Language", "%s", lang); } /* Authentication */ if (res->username != NULL) vlc_http_msg_add_creds_basic(req, false, res->username, res->password); /* Request context */ if (res->agent != NULL) vlc_http_msg_add_agent(req, res->agent); if (res->referrer != NULL) /* TODO: validate URL */ vlc_http_msg_add_header(req, "Referer", "%s", res->referrer); vlc_http_msg_add_cookies(req, vlc_http_mgr_get_jar(res->manager)); /* TODO: vlc_http_msg_add_header(req, "TE", "gzip, deflate"); */ if (res->cbs->request_format(res, req, opaque)) { vlc_http_msg_destroy(req); return NULL; } return req; }
static struct vlc_http_msg *vlc_http_tunnel_open(struct vlc_http_conn *conn, const char *hostname, unsigned port) { char *authority = vlc_http_authority(hostname, port); if (authority == NULL) return NULL; struct vlc_http_msg *req = vlc_http_req_create("CONNECT", NULL, authority, NULL); free(authority); if (unlikely(req == NULL)) return NULL; vlc_http_msg_add_header(req, "ALPN", "h2, http%%2F1.1"); vlc_http_msg_add_agent(req, PACKAGE_NAME "/" PACKAGE_VERSION); struct vlc_http_stream *stream = vlc_http_stream_open(conn, req); vlc_http_msg_destroy(req); if (stream == NULL) return NULL; struct vlc_http_msg *resp = vlc_http_msg_get_initial(stream); resp = vlc_http_msg_get_final(resp); if (resp == NULL) return NULL; int status = vlc_http_msg_get_status(resp); if ((status / 100) != 2) { vlc_http_msg_destroy(resp); resp = NULL; } return resp; }