You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1239 lines
40KB

  1. /*
  2. * HTTP protocol for ffmpeg client
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avstring.h"
  22. #include "avformat.h"
  23. #include "internal.h"
  24. #include "network.h"
  25. #include "http.h"
  26. #include "os_support.h"
  27. #include "httpauth.h"
  28. #include "url.h"
  29. #include "libavutil/opt.h"
  30. #if CONFIG_ZLIB
  31. #include <zlib.h>
  32. #endif
  33. /* XXX: POST protocol is not completely implemented because ffmpeg uses
  34. only a subset of it. */
  35. /* The IO buffer size is unrelated to the max URL size in itself, but needs
  36. * to be large enough to fit the full request headers (including long
  37. * path names).
  38. */
  39. #define BUFFER_SIZE MAX_URL_SIZE
  40. #define MAX_REDIRECTS 8
  41. typedef struct {
  42. const AVClass *class;
  43. URLContext *hd;
  44. unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
  45. int line_count;
  46. int http_code;
  47. /* Used if "Transfer-Encoding: chunked" otherwise -1. */
  48. int64_t chunksize;
  49. int64_t off, end_off, filesize;
  50. char *location;
  51. HTTPAuthState auth_state;
  52. HTTPAuthState proxy_auth_state;
  53. char *headers;
  54. char *mime_type;
  55. char *user_agent;
  56. char *content_type;
  57. /* Set if the server correctly handles Connection: close and will close
  58. * the connection after feeding us the content. */
  59. int willclose;
  60. int seekable; /**< Control seekability, 0 = disable, 1 = enable, -1 = probe. */
  61. int chunked_post;
  62. /* A flag which indicates if the end of chunked encoding has been sent. */
  63. int end_chunked_post;
  64. /* A flag which indicates we have finished to read POST reply. */
  65. int end_header;
  66. /* A flag which indicates if we use persistent connections. */
  67. int multiple_requests;
  68. uint8_t *post_data;
  69. int post_datalen;
  70. int is_akamai;
  71. int is_mediagateway;
  72. char *cookies; ///< holds newline (\n) delimited Set-Cookie header field values (without the "Set-Cookie: " field name)
  73. int icy;
  74. /* how much data was read since the last ICY metadata packet */
  75. int icy_data_read;
  76. /* after how many bytes of read data a new metadata packet will be found */
  77. int icy_metaint;
  78. char *icy_metadata_headers;
  79. char *icy_metadata_packet;
  80. #if CONFIG_ZLIB
  81. int compressed;
  82. z_stream inflate_stream;
  83. uint8_t *inflate_buffer;
  84. #endif
  85. AVDictionary *chained_options;
  86. int send_expect_100;
  87. } HTTPContext;
  88. #define OFFSET(x) offsetof(HTTPContext, x)
  89. #define D AV_OPT_FLAG_DECODING_PARAM
  90. #define E AV_OPT_FLAG_ENCODING_PARAM
  91. #define DEFAULT_USER_AGENT "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION)
  92. static const AVOption options[] = {
  93. {"seekable", "control seekability of connection", OFFSET(seekable), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, D },
  94. {"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
  95. {"headers", "set custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
  96. {"content_type", "set a specific content type for the POST messages", OFFSET(content_type), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
  97. {"user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = DEFAULT_USER_AGENT}, 0, 0, D },
  98. {"user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = DEFAULT_USER_AGENT}, 0, 0, D },
  99. {"multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E },
  100. {"post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E },
  101. {"mime_type", "export the MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, {0}, 0, 0, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
  102. {"cookies", "set cookies to be sent in applicable future requests, use newline delimited Set-Cookie HTTP field value syntax", OFFSET(cookies), AV_OPT_TYPE_STRING, {0}, 0, 0, D },
  103. {"icy", "request ICY metadata", OFFSET(icy), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D },
  104. {"icy_metadata_headers", "return ICY metadata headers", OFFSET(icy_metadata_headers), AV_OPT_TYPE_STRING, {0}, 0, 0, AV_OPT_FLAG_EXPORT },
  105. {"icy_metadata_packet", "return current ICY metadata packet", OFFSET(icy_metadata_packet), AV_OPT_TYPE_STRING, {0}, 0, 0, AV_OPT_FLAG_EXPORT },
  106. {"auth_type", "HTTP authentication type", OFFSET(auth_state.auth_type), AV_OPT_TYPE_INT, {.i64 = HTTP_AUTH_NONE}, HTTP_AUTH_NONE, HTTP_AUTH_BASIC, D|E, "auth_type" },
  107. {"none", "No auth method set, autodetect", 0, AV_OPT_TYPE_CONST, {.i64 = HTTP_AUTH_NONE}, 0, 0, D|E, "auth_type" },
  108. {"basic", "HTTP basic authentication", 0, AV_OPT_TYPE_CONST, {.i64 = HTTP_AUTH_BASIC}, 0, 0, D|E, "auth_type" },
  109. {"send_expect_100", "Force sending an Expect: 100-continue header for POST", OFFSET(send_expect_100), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, E },
  110. {"location", "The actual location of the data received", OFFSET(location), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
  111. {"offset", "initial byte offset", OFFSET(off), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, D },
  112. {"end_offset", "try to limit the request to bytes preceding this offset", OFFSET(end_off), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, D },
  113. {NULL}
  114. };
  115. #define HTTP_CLASS(flavor)\
  116. static const AVClass flavor ## _context_class = {\
  117. .class_name = #flavor,\
  118. .item_name = av_default_item_name,\
  119. .option = options,\
  120. .version = LIBAVUTIL_VERSION_INT,\
  121. }
  122. HTTP_CLASS(http);
  123. HTTP_CLASS(https);
  124. static int http_connect(URLContext *h, const char *path, const char *local_path,
  125. const char *hoststr, const char *auth,
  126. const char *proxyauth, int *new_location);
  127. void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
  128. {
  129. memcpy(&((HTTPContext*)dest->priv_data)->auth_state,
  130. &((HTTPContext*)src->priv_data)->auth_state, sizeof(HTTPAuthState));
  131. memcpy(&((HTTPContext*)dest->priv_data)->proxy_auth_state,
  132. &((HTTPContext*)src->priv_data)->proxy_auth_state,
  133. sizeof(HTTPAuthState));
  134. }
  135. /* return non zero if error */
  136. static int http_open_cnx(URLContext *h, AVDictionary **options)
  137. {
  138. const char *path, *proxy_path, *lower_proto = "tcp", *local_path;
  139. char hostname[1024], hoststr[1024], proto[10];
  140. char auth[1024], proxyauth[1024] = "";
  141. char path1[MAX_URL_SIZE];
  142. char buf[1024], urlbuf[MAX_URL_SIZE];
  143. int port, use_proxy, err, location_changed = 0, redirects = 0, attempts = 0;
  144. HTTPAuthType cur_auth_type, cur_proxy_auth_type;
  145. HTTPContext *s = h->priv_data;
  146. /* fill the dest addr */
  147. redo:
  148. /* needed in any case to build the host string */
  149. av_url_split(proto, sizeof(proto), auth, sizeof(auth),
  150. hostname, sizeof(hostname), &port,
  151. path1, sizeof(path1), s->location);
  152. ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
  153. proxy_path = getenv("http_proxy");
  154. use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), hostname) &&
  155. proxy_path != NULL && av_strstart(proxy_path, "http://", NULL);
  156. if (!strcmp(proto, "https")) {
  157. lower_proto = "tls";
  158. use_proxy = 0;
  159. if (port < 0)
  160. port = 443;
  161. }
  162. if (port < 0)
  163. port = 80;
  164. if (path1[0] == '\0')
  165. path = "/";
  166. else
  167. path = path1;
  168. local_path = path;
  169. if (use_proxy) {
  170. /* Reassemble the request URL without auth string - we don't
  171. * want to leak the auth to the proxy. */
  172. ff_url_join(urlbuf, sizeof(urlbuf), proto, NULL, hostname, port, "%s",
  173. path1);
  174. path = urlbuf;
  175. av_url_split(NULL, 0, proxyauth, sizeof(proxyauth),
  176. hostname, sizeof(hostname), &port, NULL, 0, proxy_path);
  177. }
  178. ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
  179. if (!s->hd) {
  180. err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
  181. &h->interrupt_callback, options);
  182. if (err < 0)
  183. goto fail;
  184. }
  185. cur_auth_type = s->auth_state.auth_type;
  186. cur_proxy_auth_type = s->auth_state.auth_type;
  187. if (http_connect(h, path, local_path, hoststr, auth, proxyauth, &location_changed) < 0)
  188. goto fail;
  189. attempts++;
  190. if (s->http_code == 401) {
  191. if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) &&
  192. s->auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
  193. ffurl_closep(&s->hd);
  194. goto redo;
  195. } else
  196. goto fail;
  197. }
  198. if (s->http_code == 407) {
  199. if ((cur_proxy_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) &&
  200. s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
  201. ffurl_closep(&s->hd);
  202. goto redo;
  203. } else
  204. goto fail;
  205. }
  206. if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)
  207. && location_changed == 1) {
  208. /* url moved, get next */
  209. ffurl_closep(&s->hd);
  210. if (redirects++ >= MAX_REDIRECTS)
  211. return AVERROR(EIO);
  212. /* Restart the authentication process with the new target, which
  213. * might use a different auth mechanism. */
  214. memset(&s->auth_state, 0, sizeof(s->auth_state));
  215. attempts = 0;
  216. location_changed = 0;
  217. goto redo;
  218. }
  219. return 0;
  220. fail:
  221. if (s->hd)
  222. ffurl_closep(&s->hd);
  223. return AVERROR(EIO);
  224. }
  225. int ff_http_do_new_request(URLContext *h, const char *uri)
  226. {
  227. HTTPContext *s = h->priv_data;
  228. AVDictionary *options = NULL;
  229. int ret;
  230. s->off = 0;
  231. s->icy_data_read = 0;
  232. av_free(s->location);
  233. s->location = av_strdup(uri);
  234. if (!s->location)
  235. return AVERROR(ENOMEM);
  236. av_dict_copy(&options, s->chained_options, 0);
  237. ret = http_open_cnx(h, &options);
  238. av_dict_free(&options);
  239. return ret;
  240. }
  241. static int http_open(URLContext *h, const char *uri, int flags,
  242. AVDictionary **options)
  243. {
  244. HTTPContext *s = h->priv_data;
  245. int ret;
  246. if( s->seekable == 1 )
  247. h->is_streamed = 0;
  248. else
  249. h->is_streamed = 1;
  250. s->filesize = -1;
  251. s->location = av_strdup(uri);
  252. if (!s->location)
  253. return AVERROR(ENOMEM);
  254. if (options)
  255. av_dict_copy(&s->chained_options, *options, 0);
  256. if (s->headers) {
  257. int len = strlen(s->headers);
  258. if (len < 2 || strcmp("\r\n", s->headers + len - 2))
  259. av_log(h, AV_LOG_WARNING, "No trailing CRLF found in HTTP header.\n");
  260. }
  261. ret = http_open_cnx(h, options);
  262. if (ret < 0)
  263. av_dict_free(&s->chained_options);
  264. return ret;
  265. }
  266. static int http_getc(HTTPContext *s)
  267. {
  268. int len;
  269. if (s->buf_ptr >= s->buf_end) {
  270. len = ffurl_read(s->hd, s->buffer, BUFFER_SIZE);
  271. if (len < 0) {
  272. return len;
  273. } else if (len == 0) {
  274. return AVERROR_EOF;
  275. } else {
  276. s->buf_ptr = s->buffer;
  277. s->buf_end = s->buffer + len;
  278. }
  279. }
  280. return *s->buf_ptr++;
  281. }
  282. static int http_get_line(HTTPContext *s, char *line, int line_size)
  283. {
  284. int ch;
  285. char *q;
  286. q = line;
  287. for(;;) {
  288. ch = http_getc(s);
  289. if (ch < 0)
  290. return ch;
  291. if (ch == '\n') {
  292. /* process line */
  293. if (q > line && q[-1] == '\r')
  294. q--;
  295. *q = '\0';
  296. return 0;
  297. } else {
  298. if ((q - line) < line_size - 1)
  299. *q++ = ch;
  300. }
  301. }
  302. }
  303. static int check_http_code(URLContext *h, int http_code, const char *end)
  304. {
  305. HTTPContext *s = h->priv_data;
  306. /* error codes are 4xx and 5xx, but regard 401 as a success, so we
  307. * don't abort until all headers have been parsed. */
  308. if (http_code >= 400 && http_code < 600 &&
  309. (http_code != 401 || s->auth_state.auth_type != HTTP_AUTH_NONE) &&
  310. (http_code != 407 || s->proxy_auth_state.auth_type != HTTP_AUTH_NONE)) {
  311. end += strspn(end, SPACE_CHARS);
  312. av_log(h, AV_LOG_WARNING, "HTTP error %d %s\n", http_code, end);
  313. return AVERROR(EIO);
  314. }
  315. return 0;
  316. }
  317. static int parse_location(HTTPContext *s, const char *p)
  318. {
  319. char redirected_location[MAX_URL_SIZE], *new_loc;
  320. ff_make_absolute_url(redirected_location, sizeof(redirected_location),
  321. s->location, p);
  322. new_loc = av_strdup(redirected_location);
  323. if (!new_loc)
  324. return AVERROR(ENOMEM);
  325. av_free(s->location);
  326. s->location = new_loc;
  327. return 0;
  328. }
  329. /* "bytes $from-$to/$document_size" */
  330. static void parse_content_range(URLContext *h, const char *p)
  331. {
  332. HTTPContext *s = h->priv_data;
  333. const char *slash;
  334. if (!strncmp(p, "bytes ", 6)) {
  335. p += 6;
  336. s->off = strtoll(p, NULL, 10);
  337. if ((slash = strchr(p, '/')) && strlen(slash) > 0)
  338. s->filesize = strtoll(slash+1, NULL, 10);
  339. }
  340. if (s->seekable == -1 && (!s->is_akamai || s->filesize != 2147483647))
  341. h->is_streamed = 0; /* we _can_ in fact seek */
  342. }
  343. static int parse_content_encoding(URLContext *h, const char *p)
  344. {
  345. HTTPContext *s = h->priv_data;
  346. if (!av_strncasecmp(p, "gzip", 4) ||
  347. !av_strncasecmp(p, "deflate", 7)) {
  348. #if CONFIG_ZLIB
  349. s->compressed = 1;
  350. inflateEnd(&s->inflate_stream);
  351. if (inflateInit2(&s->inflate_stream, 32 + 15) != Z_OK) {
  352. av_log(h, AV_LOG_WARNING, "Error during zlib initialisation: %s\n",
  353. s->inflate_stream.msg);
  354. return AVERROR(ENOSYS);
  355. }
  356. if (zlibCompileFlags() & (1 << 17)) {
  357. av_log(h, AV_LOG_WARNING,
  358. "Your zlib was compiled without gzip support.\n");
  359. return AVERROR(ENOSYS);
  360. }
  361. #else
  362. av_log(h, AV_LOG_WARNING,
  363. "Compressed (%s) content, need zlib with gzip support\n", p);
  364. return AVERROR(ENOSYS);
  365. #endif
  366. } else if (!av_strncasecmp(p, "identity", 8)) {
  367. // The normal, no-encoding case (although servers shouldn't include
  368. // the header at all if this is the case).
  369. } else {
  370. av_log(h, AV_LOG_WARNING, "Unknown content coding: %s\n", p);
  371. }
  372. return 0;
  373. }
  374. // Concat all Icy- header lines
  375. static int parse_icy(HTTPContext *s, const char *tag, const char *p)
  376. {
  377. int len = 4 + strlen(p) + strlen(tag);
  378. int is_first = !s->icy_metadata_headers;
  379. int ret;
  380. if (s->icy_metadata_headers)
  381. len += strlen(s->icy_metadata_headers);
  382. if ((ret = av_reallocp(&s->icy_metadata_headers, len)) < 0)
  383. return ret;
  384. if (is_first)
  385. *s->icy_metadata_headers = '\0';
  386. av_strlcatf(s->icy_metadata_headers, len, "%s: %s\n", tag, p);
  387. return 0;
  388. }
  389. static int process_line(URLContext *h, char *line, int line_count,
  390. int *new_location)
  391. {
  392. HTTPContext *s = h->priv_data;
  393. char *tag, *p, *end;
  394. int ret;
  395. /* end of header */
  396. if (line[0] == '\0') {
  397. s->end_header = 1;
  398. return 0;
  399. }
  400. p = line;
  401. if (line_count == 0) {
  402. while (!av_isspace(*p) && *p != '\0')
  403. p++;
  404. while (av_isspace(*p))
  405. p++;
  406. s->http_code = strtol(p, &end, 10);
  407. av_log(h, AV_LOG_DEBUG, "http_code=%d\n", s->http_code);
  408. if ((ret = check_http_code(h, s->http_code, end)) < 0)
  409. return ret;
  410. } else {
  411. while (*p != '\0' && *p != ':')
  412. p++;
  413. if (*p != ':')
  414. return 1;
  415. *p = '\0';
  416. tag = line;
  417. p++;
  418. while (av_isspace(*p))
  419. p++;
  420. if (!av_strcasecmp(tag, "Location")) {
  421. if ((ret = parse_location(s, p)) < 0)
  422. return ret;
  423. *new_location = 1;
  424. } else if (!av_strcasecmp(tag, "Content-Length") && s->filesize == -1) {
  425. s->filesize = strtoll(p, NULL, 10);
  426. } else if (!av_strcasecmp(tag, "Content-Range")) {
  427. parse_content_range(h, p);
  428. } else if (!av_strcasecmp(tag, "Accept-Ranges") &&
  429. !strncmp(p, "bytes", 5) &&
  430. s->seekable == -1) {
  431. h->is_streamed = 0;
  432. } else if (!av_strcasecmp(tag, "Transfer-Encoding") &&
  433. !av_strncasecmp(p, "chunked", 7)) {
  434. s->filesize = -1;
  435. s->chunksize = 0;
  436. } else if (!av_strcasecmp(tag, "WWW-Authenticate")) {
  437. ff_http_auth_handle_header(&s->auth_state, tag, p);
  438. } else if (!av_strcasecmp(tag, "Authentication-Info")) {
  439. ff_http_auth_handle_header(&s->auth_state, tag, p);
  440. } else if (!av_strcasecmp(tag, "Proxy-Authenticate")) {
  441. ff_http_auth_handle_header(&s->proxy_auth_state, tag, p);
  442. } else if (!av_strcasecmp(tag, "Connection")) {
  443. if (!strcmp(p, "close"))
  444. s->willclose = 1;
  445. } else if (!av_strcasecmp (tag, "Server")) {
  446. if (!av_strcasecmp (p, "AkamaiGHost")) {
  447. s->is_akamai = 1;
  448. } else if (!av_strncasecmp (p, "MediaGateway", 12)) {
  449. s->is_mediagateway = 1;
  450. }
  451. } else if (!av_strcasecmp (tag, "Content-Type")) {
  452. av_free(s->mime_type);
  453. s->mime_type = av_strdup(p);
  454. } else if (!av_strcasecmp (tag, "Set-Cookie")) {
  455. if (!s->cookies) {
  456. if (!(s->cookies = av_strdup(p)))
  457. return AVERROR(ENOMEM);
  458. } else {
  459. char *tmp = s->cookies;
  460. size_t str_size = strlen(tmp) + strlen(p) + 2;
  461. if (!(s->cookies = av_malloc(str_size))) {
  462. s->cookies = tmp;
  463. return AVERROR(ENOMEM);
  464. }
  465. snprintf(s->cookies, str_size, "%s\n%s", tmp, p);
  466. av_free(tmp);
  467. }
  468. } else if (!av_strcasecmp (tag, "Icy-MetaInt")) {
  469. s->icy_metaint = strtoll(p, NULL, 10);
  470. } else if (!av_strncasecmp(tag, "Icy-", 4)) {
  471. if ((ret = parse_icy(s, tag, p)) < 0)
  472. return ret;
  473. } else if (!av_strcasecmp(tag, "Content-Encoding")) {
  474. if ((ret = parse_content_encoding(h, p)) < 0)
  475. return ret;
  476. }
  477. }
  478. return 1;
  479. }
  480. /**
  481. * Create a string containing cookie values for use as a HTTP cookie header
  482. * field value for a particular path and domain from the cookie values stored in
  483. * the HTTP protocol context. The cookie string is stored in *cookies.
  484. *
  485. * @return a negative value if an error condition occurred, 0 otherwise
  486. */
  487. static int get_cookies(HTTPContext *s, char **cookies, const char *path,
  488. const char *domain)
  489. {
  490. // cookie strings will look like Set-Cookie header field values. Multiple
  491. // Set-Cookie fields will result in multiple values delimited by a newline
  492. int ret = 0;
  493. char *next, *cookie, *set_cookies = av_strdup(s->cookies), *cset_cookies = set_cookies;
  494. if (!set_cookies) return AVERROR(EINVAL);
  495. *cookies = NULL;
  496. while ((cookie = av_strtok(set_cookies, "\n", &next))) {
  497. int domain_offset = 0;
  498. char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL;
  499. set_cookies = NULL;
  500. while ((param = av_strtok(cookie, "; ", &next_param))) {
  501. cookie = NULL;
  502. if (!av_strncasecmp("path=", param, 5)) {
  503. av_free(cpath);
  504. cpath = av_strdup(&param[5]);
  505. } else if (!av_strncasecmp("domain=", param, 7)) {
  506. // if the cookie specifies a sub-domain, skip the leading dot thereby
  507. // supporting URLs that point to sub-domains and the master domain
  508. int leading_dot = (param[7] == '.');
  509. av_free(cdomain);
  510. cdomain = av_strdup(&param[7+leading_dot]);
  511. } else if (!av_strncasecmp("secure", param, 6) ||
  512. !av_strncasecmp("comment", param, 7) ||
  513. !av_strncasecmp("max-age", param, 7) ||
  514. !av_strncasecmp("version", param, 7)) {
  515. // ignore Comment, Max-Age, Secure and Version
  516. } else {
  517. av_free(cvalue);
  518. cvalue = av_strdup(param);
  519. }
  520. }
  521. if (!cdomain)
  522. cdomain = av_strdup(domain);
  523. // ensure all of the necessary values are valid
  524. if (!cdomain || !cpath || !cvalue) {
  525. av_log(s, AV_LOG_WARNING,
  526. "Invalid cookie found, no value, path or domain specified\n");
  527. goto done_cookie;
  528. }
  529. // check if the request path matches the cookie path
  530. if (av_strncasecmp(path, cpath, strlen(cpath)))
  531. goto done_cookie;
  532. // the domain should be at least the size of our cookie domain
  533. domain_offset = strlen(domain) - strlen(cdomain);
  534. if (domain_offset < 0)
  535. goto done_cookie;
  536. // match the cookie domain
  537. if (av_strcasecmp(&domain[domain_offset], cdomain))
  538. goto done_cookie;
  539. // cookie parameters match, so copy the value
  540. if (!*cookies) {
  541. if (!(*cookies = av_strdup(cvalue))) {
  542. ret = AVERROR(ENOMEM);
  543. goto done_cookie;
  544. }
  545. } else {
  546. char *tmp = *cookies;
  547. size_t str_size = strlen(cvalue) + strlen(*cookies) + 3;
  548. if (!(*cookies = av_malloc(str_size))) {
  549. ret = AVERROR(ENOMEM);
  550. goto done_cookie;
  551. }
  552. snprintf(*cookies, str_size, "%s; %s", tmp, cvalue);
  553. av_free(tmp);
  554. }
  555. done_cookie:
  556. av_free(cdomain);
  557. av_free(cpath);
  558. av_free(cvalue);
  559. if (ret < 0) {
  560. if (*cookies) av_freep(cookies);
  561. av_free(cset_cookies);
  562. return ret;
  563. }
  564. }
  565. av_free(cset_cookies);
  566. return 0;
  567. }
  568. static inline int has_header(const char *str, const char *header)
  569. {
  570. /* header + 2 to skip over CRLF prefix. (make sure you have one!) */
  571. if (!str)
  572. return 0;
  573. return av_stristart(str, header + 2, NULL) || av_stristr(str, header);
  574. }
  575. static int http_read_header(URLContext *h, int *new_location)
  576. {
  577. HTTPContext *s = h->priv_data;
  578. char line[MAX_URL_SIZE];
  579. int err = 0;
  580. s->chunksize = -1;
  581. for (;;) {
  582. if ((err = http_get_line(s, line, sizeof(line))) < 0)
  583. return err;
  584. av_log(h, AV_LOG_DEBUG, "header='%s'\n", line);
  585. err = process_line(h, line, s->line_count, new_location);
  586. if (err < 0)
  587. return err;
  588. if (err == 0)
  589. break;
  590. s->line_count++;
  591. }
  592. if (s->seekable == -1 && s->is_mediagateway && s->filesize == 2000000000)
  593. h->is_streamed = 1; /* we can in fact _not_ seek */
  594. return err;
  595. }
  596. static int http_connect(URLContext *h, const char *path, const char *local_path,
  597. const char *hoststr, const char *auth,
  598. const char *proxyauth, int *new_location)
  599. {
  600. HTTPContext *s = h->priv_data;
  601. int post, err;
  602. char headers[4096] = "";
  603. char *authstr = NULL, *proxyauthstr = NULL;
  604. int64_t off = s->off;
  605. int len = 0;
  606. const char *method;
  607. int send_expect_100 = 0;
  608. /* send http header */
  609. post = h->flags & AVIO_FLAG_WRITE;
  610. if (s->post_data) {
  611. /* force POST method and disable chunked encoding when
  612. * custom HTTP post data is set */
  613. post = 1;
  614. s->chunked_post = 0;
  615. }
  616. method = post ? "POST" : "GET";
  617. authstr = ff_http_auth_create_response(&s->auth_state, auth, local_path,
  618. method);
  619. proxyauthstr = ff_http_auth_create_response(&s->proxy_auth_state, proxyauth,
  620. local_path, method);
  621. if (post && !s->post_data) {
  622. send_expect_100 = s->send_expect_100;
  623. /* The user has supplied authentication but we don't know the auth type,
  624. * send Expect: 100-continue to get the 401 response including the
  625. * WWW-Authenticate header, or an 100 continue if no auth actually
  626. * is needed. */
  627. if (auth && *auth &&
  628. s->auth_state.auth_type == HTTP_AUTH_NONE &&
  629. s->http_code != 401)
  630. send_expect_100 = 1;
  631. }
  632. /* set default headers if needed */
  633. if (!has_header(s->headers, "\r\nUser-Agent: "))
  634. len += av_strlcatf(headers + len, sizeof(headers) - len,
  635. "User-Agent: %s\r\n", s->user_agent);
  636. if (!has_header(s->headers, "\r\nAccept: "))
  637. len += av_strlcpy(headers + len, "Accept: */*\r\n",
  638. sizeof(headers) - len);
  639. // Note: we send this on purpose even when s->off is 0 when we're probing,
  640. // since it allows us to detect more reliably if a (non-conforming)
  641. // server supports seeking by analysing the reply headers.
  642. if (!has_header(s->headers, "\r\nRange: ") && !post && (s->off > 0 || s->end_off || s->seekable == -1)) {
  643. len += av_strlcatf(headers + len, sizeof(headers) - len,
  644. "Range: bytes=%"PRId64"-", s->off);
  645. if (s->end_off)
  646. len += av_strlcatf(headers + len, sizeof(headers) - len,
  647. "%"PRId64, s->end_off - 1);
  648. len += av_strlcpy(headers + len, "\r\n",
  649. sizeof(headers) - len);
  650. }
  651. if (send_expect_100 && !has_header(s->headers, "\r\nExpect: "))
  652. len += av_strlcatf(headers + len, sizeof(headers) - len,
  653. "Expect: 100-continue\r\n");
  654. if (!has_header(s->headers, "\r\nConnection: ")) {
  655. if (s->multiple_requests) {
  656. len += av_strlcpy(headers + len, "Connection: keep-alive\r\n",
  657. sizeof(headers) - len);
  658. } else {
  659. len += av_strlcpy(headers + len, "Connection: close\r\n",
  660. sizeof(headers) - len);
  661. }
  662. }
  663. if (!has_header(s->headers, "\r\nHost: "))
  664. len += av_strlcatf(headers + len, sizeof(headers) - len,
  665. "Host: %s\r\n", hoststr);
  666. if (!has_header(s->headers, "\r\nContent-Length: ") && s->post_data)
  667. len += av_strlcatf(headers + len, sizeof(headers) - len,
  668. "Content-Length: %d\r\n", s->post_datalen);
  669. if (!has_header(s->headers, "\r\nContent-Type: ") && s->content_type)
  670. len += av_strlcatf(headers + len, sizeof(headers) - len,
  671. "Content-Type: %s\r\n", s->content_type);
  672. if (!has_header(s->headers, "\r\nCookie: ") && s->cookies) {
  673. char *cookies = NULL;
  674. if (!get_cookies(s, &cookies, path, hoststr) && cookies) {
  675. len += av_strlcatf(headers + len, sizeof(headers) - len,
  676. "Cookie: %s\r\n", cookies);
  677. av_free(cookies);
  678. }
  679. }
  680. if (!has_header(s->headers, "\r\nIcy-MetaData: ") && s->icy) {
  681. len += av_strlcatf(headers + len, sizeof(headers) - len,
  682. "Icy-MetaData: %d\r\n", 1);
  683. }
  684. /* now add in custom headers */
  685. if (s->headers)
  686. av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
  687. snprintf(s->buffer, sizeof(s->buffer),
  688. "%s %s HTTP/1.1\r\n"
  689. "%s"
  690. "%s"
  691. "%s"
  692. "%s%s"
  693. "\r\n",
  694. method,
  695. path,
  696. post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : "",
  697. headers,
  698. authstr ? authstr : "",
  699. proxyauthstr ? "Proxy-" : "", proxyauthstr ? proxyauthstr : "");
  700. av_log(h, AV_LOG_DEBUG, "request: %s\n", s->buffer);
  701. if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
  702. goto done;
  703. if (s->post_data)
  704. if ((err = ffurl_write(s->hd, s->post_data, s->post_datalen)) < 0)
  705. goto done;
  706. /* init input buffer */
  707. s->buf_ptr = s->buffer;
  708. s->buf_end = s->buffer;
  709. s->line_count = 0;
  710. s->off = 0;
  711. s->icy_data_read = 0;
  712. s->filesize = -1;
  713. s->willclose = 0;
  714. s->end_chunked_post = 0;
  715. s->end_header = 0;
  716. if (post && !s->post_data && !send_expect_100) {
  717. /* Pretend that it did work. We didn't read any header yet, since
  718. * we've still to send the POST data, but the code calling this
  719. * function will check http_code after we return. */
  720. s->http_code = 200;
  721. err = 0;
  722. goto done;
  723. }
  724. /* wait for header */
  725. err = http_read_header(h, new_location);
  726. if (err < 0)
  727. goto done;
  728. err = (off == s->off) ? 0 : -1;
  729. done:
  730. av_freep(&authstr);
  731. av_freep(&proxyauthstr);
  732. return err;
  733. }
  734. static int http_buf_read(URLContext *h, uint8_t *buf, int size)
  735. {
  736. HTTPContext *s = h->priv_data;
  737. int len;
  738. /* read bytes from input buffer first */
  739. len = s->buf_end - s->buf_ptr;
  740. if (len > 0) {
  741. if (len > size)
  742. len = size;
  743. memcpy(buf, s->buf_ptr, len);
  744. s->buf_ptr += len;
  745. } else {
  746. if (!s->willclose && s->filesize >= 0 && s->off >= s->filesize)
  747. return AVERROR_EOF;
  748. len = ffurl_read(s->hd, buf, size);
  749. }
  750. if (len > 0) {
  751. s->off += len;
  752. if (s->chunksize > 0)
  753. s->chunksize -= len;
  754. }
  755. return len;
  756. }
  757. #if CONFIG_ZLIB
  758. #define DECOMPRESS_BUF_SIZE (256 * 1024)
  759. static int http_buf_read_compressed(URLContext *h, uint8_t *buf, int size)
  760. {
  761. HTTPContext *s = h->priv_data;
  762. int ret;
  763. if (!s->inflate_buffer) {
  764. s->inflate_buffer = av_malloc(DECOMPRESS_BUF_SIZE);
  765. if (!s->inflate_buffer)
  766. return AVERROR(ENOMEM);
  767. }
  768. if (s->inflate_stream.avail_in == 0) {
  769. int read = http_buf_read(h, s->inflate_buffer, DECOMPRESS_BUF_SIZE);
  770. if (read <= 0)
  771. return read;
  772. s->inflate_stream.next_in = s->inflate_buffer;
  773. s->inflate_stream.avail_in = read;
  774. }
  775. s->inflate_stream.avail_out = size;
  776. s->inflate_stream.next_out = buf;
  777. ret = inflate(&s->inflate_stream, Z_SYNC_FLUSH);
  778. if (ret != Z_OK && ret != Z_STREAM_END)
  779. av_log(h, AV_LOG_WARNING, "inflate return value: %d, %s\n", ret, s->inflate_stream.msg);
  780. return size - s->inflate_stream.avail_out;
  781. }
  782. #endif
  783. static int http_read_stream(URLContext *h, uint8_t *buf, int size)
  784. {
  785. HTTPContext *s = h->priv_data;
  786. int err, new_location;
  787. if (!s->hd)
  788. return AVERROR_EOF;
  789. if (s->end_chunked_post && !s->end_header) {
  790. err = http_read_header(h, &new_location);
  791. if (err < 0)
  792. return err;
  793. }
  794. if (s->chunksize >= 0) {
  795. if (!s->chunksize) {
  796. char line[32];
  797. do {
  798. if ((err = http_get_line(s, line, sizeof(line))) < 0)
  799. return err;
  800. } while (!*line); /* skip CR LF from last chunk */
  801. s->chunksize = strtoll(line, NULL, 16);
  802. av_dlog(NULL, "Chunked encoding data size: %"PRId64"'\n", s->chunksize);
  803. if (!s->chunksize)
  804. return 0;
  805. }
  806. size = FFMIN(size, s->chunksize);
  807. }
  808. #if CONFIG_ZLIB
  809. if (s->compressed)
  810. return http_buf_read_compressed(h, buf, size);
  811. #endif
  812. return http_buf_read(h, buf, size);
  813. }
  814. // Like http_read_stream(), but no short reads.
  815. // Assumes partial reads are an error.
  816. static int http_read_stream_all(URLContext *h, uint8_t *buf, int size)
  817. {
  818. int pos = 0;
  819. while (pos < size) {
  820. int len = http_read_stream(h, buf + pos, size - pos);
  821. if (len < 0)
  822. return len;
  823. pos += len;
  824. }
  825. return pos;
  826. }
  827. static int store_icy(URLContext *h, int size)
  828. {
  829. HTTPContext *s = h->priv_data;
  830. /* until next metadata packet */
  831. int remaining = s->icy_metaint - s->icy_data_read;
  832. if (remaining < 0)
  833. return AVERROR_INVALIDDATA;
  834. if (!remaining) {
  835. // The metadata packet is variable sized. It has a 1 byte header
  836. // which sets the length of the packet (divided by 16). If it's 0,
  837. // the metadata doesn't change. After the packet, icy_metaint bytes
  838. // of normal data follow.
  839. uint8_t ch;
  840. int len = http_read_stream_all(h, &ch, 1);
  841. if (len < 0)
  842. return len;
  843. if (ch > 0) {
  844. char data[255 * 16 + 1];
  845. int ret;
  846. len = ch * 16;
  847. ret = http_read_stream_all(h, data, len);
  848. if (ret < 0)
  849. return ret;
  850. data[len + 1] = 0;
  851. if ((ret = av_opt_set(s, "icy_metadata_packet", data, 0)) < 0)
  852. return ret;
  853. }
  854. s->icy_data_read = 0;
  855. remaining = s->icy_metaint;
  856. }
  857. return FFMIN(size, remaining);
  858. }
  859. static int http_read(URLContext *h, uint8_t *buf, int size)
  860. {
  861. HTTPContext *s = h->priv_data;
  862. if (s->icy_metaint > 0) {
  863. size = store_icy(h, size);
  864. if (size < 0)
  865. return size;
  866. }
  867. size = http_read_stream(h, buf, size);
  868. if (size > 0)
  869. s->icy_data_read += size;
  870. return size;
  871. }
  872. /* used only when posting data */
  873. static int http_write(URLContext *h, const uint8_t *buf, int size)
  874. {
  875. char temp[11] = ""; /* 32-bit hex + CRLF + nul */
  876. int ret;
  877. char crlf[] = "\r\n";
  878. HTTPContext *s = h->priv_data;
  879. if (!s->chunked_post) {
  880. /* non-chunked data is sent without any special encoding */
  881. return ffurl_write(s->hd, buf, size);
  882. }
  883. /* silently ignore zero-size data since chunk encoding that would
  884. * signal EOF */
  885. if (size > 0) {
  886. /* upload data using chunked encoding */
  887. snprintf(temp, sizeof(temp), "%x\r\n", size);
  888. if ((ret = ffurl_write(s->hd, temp, strlen(temp))) < 0 ||
  889. (ret = ffurl_write(s->hd, buf, size)) < 0 ||
  890. (ret = ffurl_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
  891. return ret;
  892. }
  893. return size;
  894. }
  895. static int http_shutdown(URLContext *h, int flags)
  896. {
  897. int ret = 0;
  898. char footer[] = "0\r\n\r\n";
  899. HTTPContext *s = h->priv_data;
  900. /* signal end of chunked encoding if used */
  901. if ((flags & AVIO_FLAG_WRITE) && s->chunked_post) {
  902. ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
  903. ret = ret > 0 ? 0 : ret;
  904. s->end_chunked_post = 1;
  905. }
  906. return ret;
  907. }
  908. static int http_close(URLContext *h)
  909. {
  910. int ret = 0;
  911. HTTPContext *s = h->priv_data;
  912. #if CONFIG_ZLIB
  913. inflateEnd(&s->inflate_stream);
  914. av_freep(&s->inflate_buffer);
  915. #endif
  916. if (!s->end_chunked_post) {
  917. /* Close the write direction by sending the end of chunked encoding. */
  918. ret = http_shutdown(h, h->flags);
  919. }
  920. if (s->hd)
  921. ffurl_closep(&s->hd);
  922. av_dict_free(&s->chained_options);
  923. return ret;
  924. }
  925. static int64_t http_seek(URLContext *h, int64_t off, int whence)
  926. {
  927. HTTPContext *s = h->priv_data;
  928. URLContext *old_hd = s->hd;
  929. int64_t old_off = s->off;
  930. uint8_t old_buf[BUFFER_SIZE];
  931. int old_buf_size, ret;
  932. AVDictionary *options = NULL;
  933. if (whence == AVSEEK_SIZE)
  934. return s->filesize;
  935. else if ((whence == SEEK_CUR && off == 0) ||
  936. (whence == SEEK_SET && off == s->off))
  937. return s->off;
  938. else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed)
  939. return AVERROR(ENOSYS);
  940. if (whence == SEEK_CUR)
  941. off += s->off;
  942. else if (whence == SEEK_END)
  943. off += s->filesize;
  944. else if (whence != SEEK_SET)
  945. return AVERROR(EINVAL);
  946. if (off < 0)
  947. return AVERROR(EINVAL);
  948. s->off = off;
  949. /* we save the old context in case the seek fails */
  950. old_buf_size = s->buf_end - s->buf_ptr;
  951. memcpy(old_buf, s->buf_ptr, old_buf_size);
  952. s->hd = NULL;
  953. /* if it fails, continue on old connection */
  954. av_dict_copy(&options, s->chained_options, 0);
  955. if ((ret = http_open_cnx(h, &options)) < 0) {
  956. av_dict_free(&options);
  957. memcpy(s->buffer, old_buf, old_buf_size);
  958. s->buf_ptr = s->buffer;
  959. s->buf_end = s->buffer + old_buf_size;
  960. s->hd = old_hd;
  961. s->off = old_off;
  962. return ret;
  963. }
  964. av_dict_free(&options);
  965. ffurl_close(old_hd);
  966. return off;
  967. }
  968. static int
  969. http_get_file_handle(URLContext *h)
  970. {
  971. HTTPContext *s = h->priv_data;
  972. return ffurl_get_file_handle(s->hd);
  973. }
  974. #if CONFIG_HTTP_PROTOCOL
  975. URLProtocol ff_http_protocol = {
  976. .name = "http",
  977. .url_open2 = http_open,
  978. .url_read = http_read,
  979. .url_write = http_write,
  980. .url_seek = http_seek,
  981. .url_close = http_close,
  982. .url_get_file_handle = http_get_file_handle,
  983. .url_shutdown = http_shutdown,
  984. .priv_data_size = sizeof(HTTPContext),
  985. .priv_data_class = &http_context_class,
  986. .flags = URL_PROTOCOL_FLAG_NETWORK,
  987. };
  988. #endif
  989. #if CONFIG_HTTPS_PROTOCOL
  990. URLProtocol ff_https_protocol = {
  991. .name = "https",
  992. .url_open2 = http_open,
  993. .url_read = http_read,
  994. .url_write = http_write,
  995. .url_seek = http_seek,
  996. .url_close = http_close,
  997. .url_get_file_handle = http_get_file_handle,
  998. .url_shutdown = http_shutdown,
  999. .priv_data_size = sizeof(HTTPContext),
  1000. .priv_data_class = &https_context_class,
  1001. .flags = URL_PROTOCOL_FLAG_NETWORK,
  1002. };
  1003. #endif
  1004. #if CONFIG_HTTPPROXY_PROTOCOL
  1005. static int http_proxy_close(URLContext *h)
  1006. {
  1007. HTTPContext *s = h->priv_data;
  1008. if (s->hd)
  1009. ffurl_closep(&s->hd);
  1010. return 0;
  1011. }
  1012. static int http_proxy_open(URLContext *h, const char *uri, int flags)
  1013. {
  1014. HTTPContext *s = h->priv_data;
  1015. char hostname[1024], hoststr[1024];
  1016. char auth[1024], pathbuf[1024], *path;
  1017. char lower_url[100];
  1018. int port, ret = 0, attempts = 0;
  1019. HTTPAuthType cur_auth_type;
  1020. char *authstr;
  1021. int new_loc;
  1022. if( s->seekable == 1 )
  1023. h->is_streamed = 0;
  1024. else
  1025. h->is_streamed = 1;
  1026. av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
  1027. pathbuf, sizeof(pathbuf), uri);
  1028. ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
  1029. path = pathbuf;
  1030. if (*path == '/')
  1031. path++;
  1032. ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port,
  1033. NULL);
  1034. redo:
  1035. ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,
  1036. &h->interrupt_callback, NULL);
  1037. if (ret < 0)
  1038. return ret;
  1039. authstr = ff_http_auth_create_response(&s->proxy_auth_state, auth,
  1040. path, "CONNECT");
  1041. snprintf(s->buffer, sizeof(s->buffer),
  1042. "CONNECT %s HTTP/1.1\r\n"
  1043. "Host: %s\r\n"
  1044. "Connection: close\r\n"
  1045. "%s%s"
  1046. "\r\n",
  1047. path,
  1048. hoststr,
  1049. authstr ? "Proxy-" : "", authstr ? authstr : "");
  1050. av_freep(&authstr);
  1051. if ((ret = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
  1052. goto fail;
  1053. s->buf_ptr = s->buffer;
  1054. s->buf_end = s->buffer;
  1055. s->line_count = 0;
  1056. s->filesize = -1;
  1057. cur_auth_type = s->proxy_auth_state.auth_type;
  1058. /* Note: This uses buffering, potentially reading more than the
  1059. * HTTP header. If tunneling a protocol where the server starts
  1060. * the conversation, we might buffer part of that here, too.
  1061. * Reading that requires using the proper ffurl_read() function
  1062. * on this URLContext, not using the fd directly (as the tls
  1063. * protocol does). This shouldn't be an issue for tls though,
  1064. * since the client starts the conversation there, so there
  1065. * is no extra data that we might buffer up here.
  1066. */
  1067. ret = http_read_header(h, &new_loc);
  1068. if (ret < 0)
  1069. goto fail;
  1070. attempts++;
  1071. if (s->http_code == 407 &&
  1072. (cur_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) &&
  1073. s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 2) {
  1074. ffurl_closep(&s->hd);
  1075. goto redo;
  1076. }
  1077. if (s->http_code < 400)
  1078. return 0;
  1079. ret = AVERROR(EIO);
  1080. fail:
  1081. http_proxy_close(h);
  1082. return ret;
  1083. }
  1084. static int http_proxy_write(URLContext *h, const uint8_t *buf, int size)
  1085. {
  1086. HTTPContext *s = h->priv_data;
  1087. return ffurl_write(s->hd, buf, size);
  1088. }
  1089. URLProtocol ff_httpproxy_protocol = {
  1090. .name = "httpproxy",
  1091. .url_open = http_proxy_open,
  1092. .url_read = http_buf_read,
  1093. .url_write = http_proxy_write,
  1094. .url_close = http_proxy_close,
  1095. .url_get_file_handle = http_get_file_handle,
  1096. .priv_data_size = sizeof(HTTPContext),
  1097. .flags = URL_PROTOCOL_FLAG_NETWORK,
  1098. };
  1099. #endif