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.

1247 lines
41KB

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