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.

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