2 * HTTP protocol for ffmpeg client
3 * Copyright (c) 2000, 2001 Fabrice Bellard
5 * This file is part of FFmpeg.
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.
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.
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
26 #endif /* CONFIG_ZLIB */
28 #include "libavutil/avassert.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/opt.h"
37 #include "os_support.h"
40 /* XXX: POST protocol is not completely implemented because ffmpeg uses
41 * only a subset of it. */
43 /* The IO buffer size is unrelated to the max URL size in itself, but needs
44 * to be large enough to fit the full request headers (including long
46 #define BUFFER_SIZE MAX_URL_SIZE
47 #define MAX_REDIRECTS 8
57 typedef struct HTTPContext {
60 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
63 /* Used if "Transfer-Encoding: chunked" otherwise -1. */
65 int64_t off, end_off, filesize;
67 HTTPAuthState auth_state;
68 HTTPAuthState proxy_auth_state;
73 /* Set if the server correctly handles Connection: close and will close
74 * the connection after feeding us the content. */
76 int seekable; /**< Control seekability, 0 = disable, 1 = enable, -1 = probe. */
78 /* A flag which indicates if the end of chunked encoding has been sent. */
80 /* A flag which indicates we have finished to read POST reply. */
82 /* A flag which indicates if we use persistent connections. */
83 int multiple_requests;
88 char *cookies; ///< holds newline (\n) delimited Set-Cookie header field values (without the "Set-Cookie: " field name)
89 /* A dictionary containing cookies keyed by cookie name */
90 AVDictionary *cookie_dict;
92 /* how much data was read since the last ICY metadata packet */
94 /* after how many bytes of read data a new metadata packet will be found */
96 char *icy_metadata_headers;
97 char *icy_metadata_packet;
98 AVDictionary *metadata;
101 z_stream inflate_stream;
102 uint8_t *inflate_buffer;
103 #endif /* CONFIG_ZLIB */
104 AVDictionary *chained_options;
112 HandshakeState handshake_step;
113 int is_connected_server;
116 #define OFFSET(x) offsetof(HTTPContext, x)
117 #define D AV_OPT_FLAG_DECODING_PARAM
118 #define E AV_OPT_FLAG_ENCODING_PARAM
119 #define DEFAULT_USER_AGENT "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION)
121 static const AVOption options[] = {
122 { "seekable", "control seekability of connection", OFFSET(seekable), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, D },
123 { "chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, E },
124 { "headers", "set custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D | E },
125 { "content_type", "set a specific content type for the POST messages", OFFSET(content_type), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D | E },
126 { "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D },
127 { "user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D },
128 { "multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D | E },
129 { "post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D | E },
130 { "mime_type", "export the MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, { 0 }, 0, 0, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
131 { "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 },
132 { "icy", "request ICY metadata", OFFSET(icy), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, D },
133 { "icy_metadata_headers", "return ICY metadata headers", OFFSET(icy_metadata_headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, AV_OPT_FLAG_EXPORT },
134 { "icy_metadata_packet", "return current ICY metadata packet", OFFSET(icy_metadata_packet), AV_OPT_TYPE_STRING, { 0 }, 0, 0, AV_OPT_FLAG_EXPORT },
135 { "metadata", "metadata read from the bitstream", OFFSET(metadata), AV_OPT_TYPE_DICT, {0}, 0, 0, AV_OPT_FLAG_EXPORT },
136 { "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"},
137 { "none", "No auth method set, autodetect", 0, AV_OPT_TYPE_CONST, { .i64 = HTTP_AUTH_NONE }, 0, 0, D | E, "auth_type"},
138 { "basic", "HTTP basic authentication", 0, AV_OPT_TYPE_CONST, { .i64 = HTTP_AUTH_BASIC }, 0, 0, D | E, "auth_type"},
139 { "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 },
140 { "location", "The actual location of the data received", OFFSET(location), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D | E },
141 { "offset", "initial byte offset", OFFSET(off), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, D },
142 { "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 },
143 { "method", "Override the HTTP method or set the expected HTTP method from a client", OFFSET(method), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D | E },
144 { "reconnect", "auto reconnect after disconnect before EOF", OFFSET(reconnect), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
145 { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, D | E },
146 { "resource", "The resource requested by a client", OFFSET(resource), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
147 { "reply_code", "The http status code to return to a client", OFFSET(reply_code), AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599, E},
151 static int http_connect(URLContext *h, const char *path, const char *local_path,
152 const char *hoststr, const char *auth,
153 const char *proxyauth, int *new_location);
154 static int http_read_header(URLContext *h, int *new_location);
156 void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
158 memcpy(&((HTTPContext *)dest->priv_data)->auth_state,
159 &((HTTPContext *)src->priv_data)->auth_state,
160 sizeof(HTTPAuthState));
161 memcpy(&((HTTPContext *)dest->priv_data)->proxy_auth_state,
162 &((HTTPContext *)src->priv_data)->proxy_auth_state,
163 sizeof(HTTPAuthState));
166 static int http_open_cnx_internal(URLContext *h, AVDictionary **options)
168 const char *path, *proxy_path, *lower_proto = "tcp", *local_path;
169 char hostname[1024], hoststr[1024], proto[10];
170 char auth[1024], proxyauth[1024] = "";
171 char path1[MAX_URL_SIZE];
172 char buf[1024], urlbuf[MAX_URL_SIZE];
173 int port, use_proxy, err, location_changed = 0;
174 HTTPContext *s = h->priv_data;
176 av_url_split(proto, sizeof(proto), auth, sizeof(auth),
177 hostname, sizeof(hostname), &port,
178 path1, sizeof(path1), s->location);
179 ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
181 proxy_path = getenv("http_proxy");
182 use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), hostname) &&
183 proxy_path && av_strstart(proxy_path, "http://", NULL);
185 if (!strcmp(proto, "https")) {
194 if (path1[0] == '\0')
200 /* Reassemble the request URL without auth string - we don't
201 * want to leak the auth to the proxy. */
202 ff_url_join(urlbuf, sizeof(urlbuf), proto, NULL, hostname, port, "%s",
205 av_url_split(NULL, 0, proxyauth, sizeof(proxyauth),
206 hostname, sizeof(hostname), &port, NULL, 0, proxy_path);
209 ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
212 err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
213 &h->interrupt_callback, options);
218 err = http_connect(h, path, local_path, hoststr,
219 auth, proxyauth, &location_changed);
223 return location_changed;
226 /* return non zero if error */
227 static int http_open_cnx(URLContext *h, AVDictionary **options)
229 HTTPAuthType cur_auth_type, cur_proxy_auth_type;
230 HTTPContext *s = h->priv_data;
231 int location_changed, attempts = 0, redirects = 0;
233 av_dict_copy(options, s->chained_options, 0);
235 cur_auth_type = s->auth_state.auth_type;
236 cur_proxy_auth_type = s->auth_state.auth_type;
238 location_changed = http_open_cnx_internal(h, options);
239 if (location_changed < 0)
243 if (s->http_code == 401) {
244 if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) &&
245 s->auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
246 ffurl_closep(&s->hd);
251 if (s->http_code == 407) {
252 if ((cur_proxy_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) &&
253 s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
254 ffurl_closep(&s->hd);
259 if ((s->http_code == 301 || s->http_code == 302 ||
260 s->http_code == 303 || s->http_code == 307) &&
261 location_changed == 1) {
262 /* url moved, get next */
263 ffurl_closep(&s->hd);
264 if (redirects++ >= MAX_REDIRECTS)
266 /* Restart the authentication process with the new target, which
267 * might use a different auth mechanism. */
268 memset(&s->auth_state, 0, sizeof(s->auth_state));
270 location_changed = 0;
277 ffurl_closep(&s->hd);
278 if (location_changed < 0)
279 return location_changed;
280 return ff_http_averror(s->http_code, AVERROR(EIO));
283 int ff_http_do_new_request(URLContext *h, const char *uri)
285 HTTPContext *s = h->priv_data;
286 AVDictionary *options = NULL;
290 s->icy_data_read = 0;
291 av_free(s->location);
292 s->location = av_strdup(uri);
294 return AVERROR(ENOMEM);
296 ret = http_open_cnx(h, &options);
297 av_dict_free(&options);
301 int ff_http_averror(int status_code, int default_averror)
303 switch (status_code) {
304 case 400: return AVERROR_HTTP_BAD_REQUEST;
305 case 401: return AVERROR_HTTP_UNAUTHORIZED;
306 case 403: return AVERROR_HTTP_FORBIDDEN;
307 case 404: return AVERROR_HTTP_NOT_FOUND;
310 if (status_code >= 400 && status_code <= 499)
311 return AVERROR_HTTP_OTHER_4XX;
312 else if (status_code >= 500)
313 return AVERROR_HTTP_SERVER_ERROR;
315 return default_averror;
318 static int http_write_reply(URLContext* h, int status_code)
320 int ret, body = 0, reply_code, message_len;
321 const char *reply_text, *content_type;
322 HTTPContext *s = h->priv_data;
323 char message[BUFFER_SIZE];
324 content_type = "text/plain";
328 switch (status_code) {
329 case AVERROR_HTTP_BAD_REQUEST:
332 reply_text = "Bad Request";
334 case AVERROR_HTTP_FORBIDDEN:
337 reply_text = "Forbidden";
339 case AVERROR_HTTP_NOT_FOUND:
342 reply_text = "Not Found";
347 content_type = "application/octet-stream";
349 case AVERROR_HTTP_SERVER_ERROR:
352 reply_text = "Internal server error";
355 return AVERROR(EINVAL);
359 message_len = snprintf(message, sizeof(message),
360 "HTTP/1.1 %03d %s\r\n"
361 "Content-Type: %s\r\n"
362 "Content-Length: %zu\r\n"
368 strlen(reply_text) + 6, // 3 digit status code + space + \r\n
373 message_len = snprintf(message, sizeof(message),
374 "HTTP/1.1 %03d %s\r\n"
375 "Content-Type: %s\r\n"
376 "Transfer-Encoding: chunked\r\n"
382 av_log(h, AV_LOG_TRACE, "HTTP reply header: \n%s----\n", message);
383 if ((ret = ffurl_write(s->hd, message, message_len)) < 0)
388 static void handle_http_errors(URLContext *h, int error)
390 av_assert0(error < 0);
391 http_write_reply(h, error);
394 static int http_handshake(URLContext *c)
396 int ret, err, new_location;
397 HTTPContext *ch = c->priv_data;
398 URLContext *cl = ch->hd;
399 switch (ch->handshake_step) {
401 av_log(c, AV_LOG_TRACE, "Lower protocol\n");
402 if ((ret = ffurl_handshake(cl) > 0))
406 ch->handshake_step = READ_HEADERS;
407 ch->is_connected_server = 1;
410 av_log(c, AV_LOG_TRACE, "Read headers\n");
411 if ((err = http_read_header(c, &new_location)) < 0) {
412 handle_http_errors(c, err);
415 ch->handshake_step = WRITE_REPLY_HEADERS;
417 case WRITE_REPLY_HEADERS:
418 av_log(c, AV_LOG_TRACE, "Reply code: %d\n", ch->reply_code);
419 if ((err = http_write_reply(c, ch->reply_code)) < 0)
421 ch->handshake_step = FINISH;
426 // this should never be reached.
427 return AVERROR(EINVAL);
430 static int http_listen(URLContext *h, const char *uri, int flags,
431 AVDictionary **options) {
432 HTTPContext *s = h->priv_data;
434 char hostname[1024], proto[10];
436 const char *lower_proto = "tcp";
438 av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
440 if (!strcmp(proto, "https"))
442 ff_url_join(lower_url, sizeof(lower_url), lower_proto, NULL, hostname, port,
444 if ((ret = av_dict_set_int(options, "listen", s->listen, 0)) < 0)
446 if ((ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,
447 &h->interrupt_callback, options)) < 0)
449 s->handshake_step = LOWER_PROTO;
450 if (s->listen == HTTP_SINGLE) { /* single client */
452 while ((ret = http_handshake(h)) > 0);
455 av_dict_free(&s->chained_options);
459 static int http_open(URLContext *h, const char *uri, int flags,
460 AVDictionary **options)
462 HTTPContext *s = h->priv_data;
465 if( s->seekable == 1 )
471 s->location = av_strdup(uri);
473 return AVERROR(ENOMEM);
475 av_dict_copy(&s->chained_options, *options, 0);
478 int len = strlen(s->headers);
479 if (len < 2 || strcmp("\r\n", s->headers + len - 2)) {
480 av_log(h, AV_LOG_WARNING,
481 "No trailing CRLF found in HTTP header.\n");
482 ret = av_reallocp(&s->headers, len + 3);
485 s->headers[len] = '\r';
486 s->headers[len + 1] = '\n';
487 s->headers[len + 2] = '\0';
492 return http_listen(h, uri, flags, options);
494 ret = http_open_cnx(h, options);
496 av_dict_free(&s->chained_options);
500 static int http_accept(URLContext *s, URLContext **c)
503 HTTPContext *sc = s->priv_data;
505 URLContext *sl = sc->hd;
506 URLContext *cl = NULL;
508 av_assert0(sc->listen);
509 if ((ret = ffurl_alloc(c, s->filename, s->flags, &sl->interrupt_callback)) < 0)
511 cc = (*c)->priv_data;
512 if ((ret = ffurl_accept(sl, &cl)) < 0)
515 cc->is_multi_client = 1;
520 static int http_getc(HTTPContext *s)
523 if (s->buf_ptr >= s->buf_end) {
524 len = ffurl_read(s->hd, s->buffer, BUFFER_SIZE);
527 } else if (len == 0) {
530 s->buf_ptr = s->buffer;
531 s->buf_end = s->buffer + len;
534 return *s->buf_ptr++;
537 static int http_get_line(HTTPContext *s, char *line, int line_size)
549 if (q > line && q[-1] == '\r')
555 if ((q - line) < line_size - 1)
561 static int check_http_code(URLContext *h, int http_code, const char *end)
563 HTTPContext *s = h->priv_data;
564 /* error codes are 4xx and 5xx, but regard 401 as a success, so we
565 * don't abort until all headers have been parsed. */
566 if (http_code >= 400 && http_code < 600 &&
567 (http_code != 401 || s->auth_state.auth_type != HTTP_AUTH_NONE) &&
568 (http_code != 407 || s->proxy_auth_state.auth_type != HTTP_AUTH_NONE)) {
569 end += strspn(end, SPACE_CHARS);
570 av_log(h, AV_LOG_WARNING, "HTTP error %d %s\n", http_code, end);
571 return ff_http_averror(http_code, AVERROR(EIO));
576 static int parse_location(HTTPContext *s, const char *p)
578 char redirected_location[MAX_URL_SIZE], *new_loc;
579 ff_make_absolute_url(redirected_location, sizeof(redirected_location),
581 new_loc = av_strdup(redirected_location);
583 return AVERROR(ENOMEM);
584 av_free(s->location);
585 s->location = new_loc;
589 /* "bytes $from-$to/$document_size" */
590 static void parse_content_range(URLContext *h, const char *p)
592 HTTPContext *s = h->priv_data;
595 if (!strncmp(p, "bytes ", 6)) {
597 s->off = strtoll(p, NULL, 10);
598 if ((slash = strchr(p, '/')) && strlen(slash) > 0)
599 s->filesize = strtoll(slash + 1, NULL, 10);
601 if (s->seekable == -1 && (!s->is_akamai || s->filesize != 2147483647))
602 h->is_streamed = 0; /* we _can_ in fact seek */
605 static int parse_content_encoding(URLContext *h, const char *p)
607 if (!av_strncasecmp(p, "gzip", 4) ||
608 !av_strncasecmp(p, "deflate", 7)) {
610 HTTPContext *s = h->priv_data;
613 inflateEnd(&s->inflate_stream);
614 if (inflateInit2(&s->inflate_stream, 32 + 15) != Z_OK) {
615 av_log(h, AV_LOG_WARNING, "Error during zlib initialisation: %s\n",
616 s->inflate_stream.msg);
617 return AVERROR(ENOSYS);
619 if (zlibCompileFlags() & (1 << 17)) {
620 av_log(h, AV_LOG_WARNING,
621 "Your zlib was compiled without gzip support.\n");
622 return AVERROR(ENOSYS);
625 av_log(h, AV_LOG_WARNING,
626 "Compressed (%s) content, need zlib with gzip support\n", p);
627 return AVERROR(ENOSYS);
628 #endif /* CONFIG_ZLIB */
629 } else if (!av_strncasecmp(p, "identity", 8)) {
630 // The normal, no-encoding case (although servers shouldn't include
631 // the header at all if this is the case).
633 av_log(h, AV_LOG_WARNING, "Unknown content coding: %s\n", p);
638 // Concat all Icy- header lines
639 static int parse_icy(HTTPContext *s, const char *tag, const char *p)
641 int len = 4 + strlen(p) + strlen(tag);
642 int is_first = !s->icy_metadata_headers;
645 av_dict_set(&s->metadata, tag, p, 0);
647 if (s->icy_metadata_headers)
648 len += strlen(s->icy_metadata_headers);
650 if ((ret = av_reallocp(&s->icy_metadata_headers, len)) < 0)
654 *s->icy_metadata_headers = '\0';
656 av_strlcatf(s->icy_metadata_headers, len, "%s: %s\n", tag, p);
661 static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies)
665 // duplicate the cookie name (dict will dupe the value)
666 if (!(eql = strchr(p, '='))) return AVERROR(EINVAL);
667 if (!(name = av_strndup(p, eql - p))) return AVERROR(ENOMEM);
669 // add the cookie to the dictionary
670 av_dict_set(cookies, name, eql, AV_DICT_DONT_STRDUP_KEY);
675 static int cookie_string(AVDictionary *dict, char **cookies)
677 AVDictionaryEntry *e = NULL;
680 // determine how much memory is needed for the cookies string
681 while (e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))
682 len += strlen(e->key) + strlen(e->value) + 1;
684 // reallocate the cookies
686 if (*cookies) av_free(*cookies);
687 *cookies = av_malloc(len);
688 if (!*cookies) return AVERROR(ENOMEM);
691 // write out the cookies
692 while (e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))
693 av_strlcatf(*cookies, len, "%s%s\n", e->key, e->value);
698 static int process_line(URLContext *h, char *line, int line_count,
701 HTTPContext *s = h->priv_data;
702 const char *auto_method = h->flags & AVIO_FLAG_READ ? "POST" : "GET";
703 char *tag, *p, *end, *method, *resource, *version;
707 if (line[0] == '\0') {
713 if (line_count == 0) {
714 if (s->is_connected_server) {
717 while (!av_isspace(*p))
720 av_log(h, AV_LOG_TRACE, "Received method: %s\n", method);
722 if (av_strcasecmp(s->method, method)) {
723 av_log(h, AV_LOG_ERROR, "Received and expected HTTP method do not match. (%s expected, %s received)\n",
725 return ff_http_averror(400, AVERROR(EIO));
728 // use autodetected HTTP method to expect
729 av_log(h, AV_LOG_TRACE, "Autodetected %s HTTP method\n", auto_method);
730 if (av_strcasecmp(auto_method, method)) {
731 av_log(h, AV_LOG_ERROR, "Received and autodetected HTTP method did not match "
732 "(%s autodetected %s received)\n", auto_method, method);
733 return ff_http_averror(400, AVERROR(EIO));
735 if (!(s->method = av_strdup(method)))
736 return AVERROR(ENOMEM);
740 while (av_isspace(*p))
743 while (!av_isspace(*p))
746 av_log(h, AV_LOG_TRACE, "Requested resource: %s\n", resource);
747 if (!(s->resource = av_strdup(resource)))
748 return AVERROR(ENOMEM);
751 while (av_isspace(*p))
754 while (!av_isspace(*p))
757 if (av_strncasecmp(version, "HTTP/", 5)) {
758 av_log(h, AV_LOG_ERROR, "Malformed HTTP version string.\n");
759 return ff_http_averror(400, AVERROR(EIO));
761 av_log(h, AV_LOG_TRACE, "HTTP version string: %s\n", version);
763 while (!av_isspace(*p) && *p != '\0')
765 while (av_isspace(*p))
767 s->http_code = strtol(p, &end, 10);
769 av_log(h, AV_LOG_TRACE, "http_code=%d\n", s->http_code);
771 if ((ret = check_http_code(h, s->http_code, end)) < 0)
775 while (*p != '\0' && *p != ':')
783 while (av_isspace(*p))
785 if (!av_strcasecmp(tag, "Location")) {
786 if ((ret = parse_location(s, p)) < 0)
789 } else if (!av_strcasecmp(tag, "Content-Length") && s->filesize == -1) {
790 s->filesize = strtoll(p, NULL, 10);
791 } else if (!av_strcasecmp(tag, "Content-Range")) {
792 parse_content_range(h, p);
793 } else if (!av_strcasecmp(tag, "Accept-Ranges") &&
794 !strncmp(p, "bytes", 5) &&
797 } else if (!av_strcasecmp(tag, "Transfer-Encoding") &&
798 !av_strncasecmp(p, "chunked", 7)) {
801 } else if (!av_strcasecmp(tag, "WWW-Authenticate")) {
802 ff_http_auth_handle_header(&s->auth_state, tag, p);
803 } else if (!av_strcasecmp(tag, "Authentication-Info")) {
804 ff_http_auth_handle_header(&s->auth_state, tag, p);
805 } else if (!av_strcasecmp(tag, "Proxy-Authenticate")) {
806 ff_http_auth_handle_header(&s->proxy_auth_state, tag, p);
807 } else if (!av_strcasecmp(tag, "Connection")) {
808 if (!strcmp(p, "close"))
810 } else if (!av_strcasecmp(tag, "Server")) {
811 if (!av_strcasecmp(p, "AkamaiGHost")) {
813 } else if (!av_strncasecmp(p, "MediaGateway", 12)) {
814 s->is_mediagateway = 1;
816 } else if (!av_strcasecmp(tag, "Content-Type")) {
817 av_free(s->mime_type);
818 s->mime_type = av_strdup(p);
819 } else if (!av_strcasecmp(tag, "Set-Cookie")) {
820 if (parse_cookie(s, p, &s->cookie_dict))
821 av_log(h, AV_LOG_WARNING, "Unable to parse '%s'\n", p);
822 } else if (!av_strcasecmp(tag, "Icy-MetaInt")) {
823 s->icy_metaint = strtoll(p, NULL, 10);
824 } else if (!av_strncasecmp(tag, "Icy-", 4)) {
825 if ((ret = parse_icy(s, tag, p)) < 0)
827 } else if (!av_strcasecmp(tag, "Content-Encoding")) {
828 if ((ret = parse_content_encoding(h, p)) < 0)
836 * Create a string containing cookie values for use as a HTTP cookie header
837 * field value for a particular path and domain from the cookie values stored in
838 * the HTTP protocol context. The cookie string is stored in *cookies.
840 * @return a negative value if an error condition occurred, 0 otherwise
842 static int get_cookies(HTTPContext *s, char **cookies, const char *path,
845 // cookie strings will look like Set-Cookie header field values. Multiple
846 // Set-Cookie fields will result in multiple values delimited by a newline
848 char *next, *cookie, *set_cookies = av_strdup(s->cookies), *cset_cookies = set_cookies;
850 if (!set_cookies) return AVERROR(EINVAL);
852 // destroy any cookies in the dictionary.
853 av_dict_free(&s->cookie_dict);
856 while ((cookie = av_strtok(set_cookies, "\n", &next))) {
857 int domain_offset = 0;
858 char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL;
861 // store the cookie in a dict in case it is updated in the response
862 if (parse_cookie(s, cookie, &s->cookie_dict))
863 av_log(s, AV_LOG_WARNING, "Unable to parse '%s'\n", cookie);
865 while ((param = av_strtok(cookie, "; ", &next_param))) {
867 // first key-value pair is the actual cookie value
868 cvalue = av_strdup(param);
870 } else if (!av_strncasecmp("path=", param, 5)) {
872 cpath = av_strdup(¶m[5]);
873 } else if (!av_strncasecmp("domain=", param, 7)) {
874 // if the cookie specifies a sub-domain, skip the leading dot thereby
875 // supporting URLs that point to sub-domains and the master domain
876 int leading_dot = (param[7] == '.');
878 cdomain = av_strdup(¶m[7+leading_dot]);
880 // ignore unknown attributes
884 cdomain = av_strdup(domain);
886 // ensure all of the necessary values are valid
887 if (!cdomain || !cpath || !cvalue) {
888 av_log(s, AV_LOG_WARNING,
889 "Invalid cookie found, no value, path or domain specified\n");
893 // check if the request path matches the cookie path
894 if (av_strncasecmp(path, cpath, strlen(cpath)))
897 // the domain should be at least the size of our cookie domain
898 domain_offset = strlen(domain) - strlen(cdomain);
899 if (domain_offset < 0)
902 // match the cookie domain
903 if (av_strcasecmp(&domain[domain_offset], cdomain))
906 // cookie parameters match, so copy the value
908 if (!(*cookies = av_strdup(cvalue))) {
909 ret = AVERROR(ENOMEM);
913 char *tmp = *cookies;
914 size_t str_size = strlen(cvalue) + strlen(*cookies) + 3;
915 if (!(*cookies = av_malloc(str_size))) {
916 ret = AVERROR(ENOMEM);
919 snprintf(*cookies, str_size, "%s; %s", tmp, cvalue);
928 if (*cookies) av_freep(cookies);
929 av_free(cset_cookies);
934 av_free(cset_cookies);
939 static inline int has_header(const char *str, const char *header)
941 /* header + 2 to skip over CRLF prefix. (make sure you have one!) */
944 return av_stristart(str, header + 2, NULL) || av_stristr(str, header);
947 static int http_read_header(URLContext *h, int *new_location)
949 HTTPContext *s = h->priv_data;
950 char line[MAX_URL_SIZE];
956 if ((err = http_get_line(s, line, sizeof(line))) < 0)
959 av_log(h, AV_LOG_TRACE, "header='%s'\n", line);
961 err = process_line(h, line, s->line_count, new_location);
969 if (s->seekable == -1 && s->is_mediagateway && s->filesize == 2000000000)
970 h->is_streamed = 1; /* we can in fact _not_ seek */
972 // add any new cookies into the existing cookie string
973 cookie_string(s->cookie_dict, &s->cookies);
974 av_dict_free(&s->cookie_dict);
979 static int http_connect(URLContext *h, const char *path, const char *local_path,
980 const char *hoststr, const char *auth,
981 const char *proxyauth, int *new_location)
983 HTTPContext *s = h->priv_data;
985 char headers[HTTP_HEADERS_SIZE] = "";
986 char *authstr = NULL, *proxyauthstr = NULL;
987 int64_t off = s->off;
990 int send_expect_100 = 0;
992 /* send http header */
993 post = h->flags & AVIO_FLAG_WRITE;
996 /* force POST method and disable chunked encoding when
997 * custom HTTP post data is set */
1005 method = post ? "POST" : "GET";
1007 authstr = ff_http_auth_create_response(&s->auth_state, auth,
1008 local_path, method);
1009 proxyauthstr = ff_http_auth_create_response(&s->proxy_auth_state, proxyauth,
1010 local_path, method);
1011 if (post && !s->post_data) {
1012 send_expect_100 = s->send_expect_100;
1013 /* The user has supplied authentication but we don't know the auth type,
1014 * send Expect: 100-continue to get the 401 response including the
1015 * WWW-Authenticate header, or an 100 continue if no auth actually
1017 if (auth && *auth &&
1018 s->auth_state.auth_type == HTTP_AUTH_NONE &&
1019 s->http_code != 401)
1020 send_expect_100 = 1;
1023 /* set default headers if needed */
1024 if (!has_header(s->headers, "\r\nUser-Agent: "))
1025 len += av_strlcatf(headers + len, sizeof(headers) - len,
1026 "User-Agent: %s\r\n", s->user_agent);
1027 if (!has_header(s->headers, "\r\nAccept: "))
1028 len += av_strlcpy(headers + len, "Accept: */*\r\n",
1029 sizeof(headers) - len);
1030 // Note: we send this on purpose even when s->off is 0 when we're probing,
1031 // since it allows us to detect more reliably if a (non-conforming)
1032 // server supports seeking by analysing the reply headers.
1033 if (!has_header(s->headers, "\r\nRange: ") && !post && (s->off > 0 || s->end_off || s->seekable == -1)) {
1034 len += av_strlcatf(headers + len, sizeof(headers) - len,
1035 "Range: bytes=%"PRId64"-", s->off);
1037 len += av_strlcatf(headers + len, sizeof(headers) - len,
1038 "%"PRId64, s->end_off - 1);
1039 len += av_strlcpy(headers + len, "\r\n",
1040 sizeof(headers) - len);
1042 if (send_expect_100 && !has_header(s->headers, "\r\nExpect: "))
1043 len += av_strlcatf(headers + len, sizeof(headers) - len,
1044 "Expect: 100-continue\r\n");
1046 if (!has_header(s->headers, "\r\nConnection: ")) {
1047 if (s->multiple_requests)
1048 len += av_strlcpy(headers + len, "Connection: keep-alive\r\n",
1049 sizeof(headers) - len);
1051 len += av_strlcpy(headers + len, "Connection: close\r\n",
1052 sizeof(headers) - len);
1055 if (!has_header(s->headers, "\r\nHost: "))
1056 len += av_strlcatf(headers + len, sizeof(headers) - len,
1057 "Host: %s\r\n", hoststr);
1058 if (!has_header(s->headers, "\r\nContent-Length: ") && s->post_data)
1059 len += av_strlcatf(headers + len, sizeof(headers) - len,
1060 "Content-Length: %d\r\n", s->post_datalen);
1062 if (!has_header(s->headers, "\r\nContent-Type: ") && s->content_type)
1063 len += av_strlcatf(headers + len, sizeof(headers) - len,
1064 "Content-Type: %s\r\n", s->content_type);
1065 if (!has_header(s->headers, "\r\nCookie: ") && s->cookies) {
1066 char *cookies = NULL;
1067 if (!get_cookies(s, &cookies, path, hoststr) && cookies) {
1068 len += av_strlcatf(headers + len, sizeof(headers) - len,
1069 "Cookie: %s\r\n", cookies);
1073 if (!has_header(s->headers, "\r\nIcy-MetaData: ") && s->icy)
1074 len += av_strlcatf(headers + len, sizeof(headers) - len,
1075 "Icy-MetaData: %d\r\n", 1);
1077 /* now add in custom headers */
1079 av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
1081 snprintf(s->buffer, sizeof(s->buffer),
1082 "%s %s HTTP/1.1\r\n"
1090 post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : "",
1092 authstr ? authstr : "",
1093 proxyauthstr ? "Proxy-" : "", proxyauthstr ? proxyauthstr : "");
1095 av_log(h, AV_LOG_DEBUG, "request: %s\n", s->buffer);
1097 if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
1101 if ((err = ffurl_write(s->hd, s->post_data, s->post_datalen)) < 0)
1104 /* init input buffer */
1105 s->buf_ptr = s->buffer;
1106 s->buf_end = s->buffer;
1109 s->icy_data_read = 0;
1112 s->end_chunked_post = 0;
1114 if (post && !s->post_data && !send_expect_100) {
1115 /* Pretend that it did work. We didn't read any header yet, since
1116 * we've still to send the POST data, but the code calling this
1117 * function will check http_code after we return. */
1123 /* wait for header */
1124 err = http_read_header(h, new_location);
1131 err = (off == s->off) ? 0 : -1;
1134 av_freep(&proxyauthstr);
1138 static int http_buf_read(URLContext *h, uint8_t *buf, int size)
1140 HTTPContext *s = h->priv_data;
1142 /* read bytes from input buffer first */
1143 len = s->buf_end - s->buf_ptr;
1147 memcpy(buf, s->buf_ptr, len);
1150 if ((!s->willclose || s->chunksize < 0) &&
1151 s->filesize >= 0 && s->off >= s->filesize)
1153 len = ffurl_read(s->hd, buf, size);
1154 if (!len && (!s->willclose || s->chunksize < 0) &&
1155 s->filesize >= 0 && s->off < s->filesize) {
1156 av_log(h, AV_LOG_ERROR,
1157 "Stream ends prematurely at %"PRId64", should be %"PRId64"\n",
1160 return AVERROR(EIO);
1165 if (s->chunksize > 0)
1166 s->chunksize -= len;
1172 #define DECOMPRESS_BUF_SIZE (256 * 1024)
1173 static int http_buf_read_compressed(URLContext *h, uint8_t *buf, int size)
1175 HTTPContext *s = h->priv_data;
1178 if (!s->inflate_buffer) {
1179 s->inflate_buffer = av_malloc(DECOMPRESS_BUF_SIZE);
1180 if (!s->inflate_buffer)
1181 return AVERROR(ENOMEM);
1184 if (s->inflate_stream.avail_in == 0) {
1185 int read = http_buf_read(h, s->inflate_buffer, DECOMPRESS_BUF_SIZE);
1188 s->inflate_stream.next_in = s->inflate_buffer;
1189 s->inflate_stream.avail_in = read;
1192 s->inflate_stream.avail_out = size;
1193 s->inflate_stream.next_out = buf;
1195 ret = inflate(&s->inflate_stream, Z_SYNC_FLUSH);
1196 if (ret != Z_OK && ret != Z_STREAM_END)
1197 av_log(h, AV_LOG_WARNING, "inflate return value: %d, %s\n",
1198 ret, s->inflate_stream.msg);
1200 return size - s->inflate_stream.avail_out;
1202 #endif /* CONFIG_ZLIB */
1204 static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int force_reconnect);
1206 static int http_read_stream(URLContext *h, uint8_t *buf, int size)
1208 HTTPContext *s = h->priv_data;
1209 int err, new_location, read_ret, seek_ret;
1214 if (s->end_chunked_post && !s->end_header) {
1215 err = http_read_header(h, &new_location);
1220 if (s->chunksize >= 0) {
1221 if (!s->chunksize) {
1225 if ((err = http_get_line(s, line, sizeof(line))) < 0)
1227 } while (!*line); /* skip CR LF from last chunk */
1229 s->chunksize = strtoll(line, NULL, 16);
1231 av_log(NULL, AV_LOG_TRACE, "Chunked encoding data size: %"PRId64"'\n",
1237 size = FFMIN(size, s->chunksize);
1241 return http_buf_read_compressed(h, buf, size);
1242 #endif /* CONFIG_ZLIB */
1243 read_ret = http_buf_read(h, buf, size);
1244 if (read_ret < 0 && s->reconnect && !h->is_streamed && s->filesize > 0 && s->off < s->filesize) {
1245 av_log(h, AV_LOG_INFO, "Will reconnect at %"PRId64".\n", s->off);
1246 seek_ret = http_seek_internal(h, s->off, SEEK_SET, 1);
1247 if (seek_ret != s->off) {
1248 av_log(h, AV_LOG_ERROR, "Failed to reconnect at %"PRId64".\n", s->off);
1252 read_ret = http_buf_read(h, buf, size);
1258 // Like http_read_stream(), but no short reads.
1259 // Assumes partial reads are an error.
1260 static int http_read_stream_all(URLContext *h, uint8_t *buf, int size)
1263 while (pos < size) {
1264 int len = http_read_stream(h, buf + pos, size - pos);
1272 static void update_metadata(HTTPContext *s, char *data)
1281 val = strstr(key, "='");
1284 end = strstr(val, "';");
1292 av_dict_set(&s->metadata, key, val, 0);
1298 static int store_icy(URLContext *h, int size)
1300 HTTPContext *s = h->priv_data;
1301 /* until next metadata packet */
1302 int remaining = s->icy_metaint - s->icy_data_read;
1305 return AVERROR_INVALIDDATA;
1308 /* The metadata packet is variable sized. It has a 1 byte header
1309 * which sets the length of the packet (divided by 16). If it's 0,
1310 * the metadata doesn't change. After the packet, icy_metaint bytes
1311 * of normal data follows. */
1313 int len = http_read_stream_all(h, &ch, 1);
1317 char data[255 * 16 + 1];
1320 ret = http_read_stream_all(h, data, len);
1324 if ((ret = av_opt_set(s, "icy_metadata_packet", data, 0)) < 0)
1326 update_metadata(s, data);
1328 s->icy_data_read = 0;
1329 remaining = s->icy_metaint;
1332 return FFMIN(size, remaining);
1335 static int http_read(URLContext *h, uint8_t *buf, int size)
1337 HTTPContext *s = h->priv_data;
1339 if (s->icy_metaint > 0) {
1340 size = store_icy(h, size);
1345 size = http_read_stream(h, buf, size);
1347 s->icy_data_read += size;
1351 /* used only when posting data */
1352 static int http_write(URLContext *h, const uint8_t *buf, int size)
1354 char temp[11] = ""; /* 32-bit hex + CRLF + nul */
1356 char crlf[] = "\r\n";
1357 HTTPContext *s = h->priv_data;
1359 if (!s->chunked_post) {
1360 /* non-chunked data is sent without any special encoding */
1361 return ffurl_write(s->hd, buf, size);
1364 /* silently ignore zero-size data since chunk encoding that would
1367 /* upload data using chunked encoding */
1368 snprintf(temp, sizeof(temp), "%x\r\n", size);
1370 if ((ret = ffurl_write(s->hd, temp, strlen(temp))) < 0 ||
1371 (ret = ffurl_write(s->hd, buf, size)) < 0 ||
1372 (ret = ffurl_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
1378 static int http_shutdown(URLContext *h, int flags)
1381 char footer[] = "0\r\n\r\n";
1382 HTTPContext *s = h->priv_data;
1384 /* signal end of chunked encoding if used */
1385 if (((flags & AVIO_FLAG_WRITE) && s->chunked_post) ||
1386 ((flags & AVIO_FLAG_READ) && s->chunked_post && s->listen)) {
1387 ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
1388 ret = ret > 0 ? 0 : ret;
1389 s->end_chunked_post = 1;
1395 static int http_close(URLContext *h)
1398 HTTPContext *s = h->priv_data;
1401 inflateEnd(&s->inflate_stream);
1402 av_freep(&s->inflate_buffer);
1403 #endif /* CONFIG_ZLIB */
1405 if (!s->end_chunked_post)
1406 /* Close the write direction by sending the end of chunked encoding. */
1407 ret = http_shutdown(h, h->flags);
1410 ffurl_closep(&s->hd);
1411 av_dict_free(&s->chained_options);
1415 static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int force_reconnect)
1417 HTTPContext *s = h->priv_data;
1418 URLContext *old_hd = s->hd;
1419 int64_t old_off = s->off;
1420 uint8_t old_buf[BUFFER_SIZE];
1421 int old_buf_size, ret;
1422 AVDictionary *options = NULL;
1424 if (whence == AVSEEK_SIZE)
1426 else if (!force_reconnect &&
1427 ((whence == SEEK_CUR && off == 0) ||
1428 (whence == SEEK_SET && off == s->off)))
1430 else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed)
1431 return AVERROR(ENOSYS);
1433 if (whence == SEEK_CUR)
1435 else if (whence == SEEK_END)
1437 else if (whence != SEEK_SET)
1438 return AVERROR(EINVAL);
1440 return AVERROR(EINVAL);
1443 /* we save the old context in case the seek fails */
1444 old_buf_size = s->buf_end - s->buf_ptr;
1445 memcpy(old_buf, s->buf_ptr, old_buf_size);
1448 /* if it fails, continue on old connection */
1449 if ((ret = http_open_cnx(h, &options)) < 0) {
1450 av_dict_free(&options);
1451 memcpy(s->buffer, old_buf, old_buf_size);
1452 s->buf_ptr = s->buffer;
1453 s->buf_end = s->buffer + old_buf_size;
1458 av_dict_free(&options);
1459 ffurl_close(old_hd);
1463 static int64_t http_seek(URLContext *h, int64_t off, int whence)
1465 return http_seek_internal(h, off, whence, 0);
1468 static int http_get_file_handle(URLContext *h)
1470 HTTPContext *s = h->priv_data;
1471 return ffurl_get_file_handle(s->hd);
1474 #define HTTP_CLASS(flavor) \
1475 static const AVClass flavor ## _context_class = { \
1476 .class_name = # flavor, \
1477 .item_name = av_default_item_name, \
1478 .option = options, \
1479 .version = LIBAVUTIL_VERSION_INT, \
1482 #if CONFIG_HTTP_PROTOCOL
1485 URLProtocol ff_http_protocol = {
1487 .url_open2 = http_open,
1488 .url_accept = http_accept,
1489 .url_handshake = http_handshake,
1490 .url_read = http_read,
1491 .url_write = http_write,
1492 .url_seek = http_seek,
1493 .url_close = http_close,
1494 .url_get_file_handle = http_get_file_handle,
1495 .url_shutdown = http_shutdown,
1496 .priv_data_size = sizeof(HTTPContext),
1497 .priv_data_class = &http_context_class,
1498 .flags = URL_PROTOCOL_FLAG_NETWORK,
1500 #endif /* CONFIG_HTTP_PROTOCOL */
1502 #if CONFIG_HTTPS_PROTOCOL
1505 URLProtocol ff_https_protocol = {
1507 .url_open2 = http_open,
1508 .url_read = http_read,
1509 .url_write = http_write,
1510 .url_seek = http_seek,
1511 .url_close = http_close,
1512 .url_get_file_handle = http_get_file_handle,
1513 .url_shutdown = http_shutdown,
1514 .priv_data_size = sizeof(HTTPContext),
1515 .priv_data_class = &https_context_class,
1516 .flags = URL_PROTOCOL_FLAG_NETWORK,
1518 #endif /* CONFIG_HTTPS_PROTOCOL */
1520 #if CONFIG_HTTPPROXY_PROTOCOL
1521 static int http_proxy_close(URLContext *h)
1523 HTTPContext *s = h->priv_data;
1525 ffurl_closep(&s->hd);
1529 static int http_proxy_open(URLContext *h, const char *uri, int flags)
1531 HTTPContext *s = h->priv_data;
1532 char hostname[1024], hoststr[1024];
1533 char auth[1024], pathbuf[1024], *path;
1534 char lower_url[100];
1535 int port, ret = 0, attempts = 0;
1536 HTTPAuthType cur_auth_type;
1540 if( s->seekable == 1 )
1545 av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
1546 pathbuf, sizeof(pathbuf), uri);
1547 ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
1552 ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port,
1555 ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,
1556 &h->interrupt_callback, NULL);
1560 authstr = ff_http_auth_create_response(&s->proxy_auth_state, auth,
1562 snprintf(s->buffer, sizeof(s->buffer),
1563 "CONNECT %s HTTP/1.1\r\n"
1565 "Connection: close\r\n"
1570 authstr ? "Proxy-" : "", authstr ? authstr : "");
1573 if ((ret = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
1576 s->buf_ptr = s->buffer;
1577 s->buf_end = s->buffer;
1580 cur_auth_type = s->proxy_auth_state.auth_type;
1582 /* Note: This uses buffering, potentially reading more than the
1583 * HTTP header. If tunneling a protocol where the server starts
1584 * the conversation, we might buffer part of that here, too.
1585 * Reading that requires using the proper ffurl_read() function
1586 * on this URLContext, not using the fd directly (as the tls
1587 * protocol does). This shouldn't be an issue for tls though,
1588 * since the client starts the conversation there, so there
1589 * is no extra data that we might buffer up here.
1591 ret = http_read_header(h, &new_loc);
1596 if (s->http_code == 407 &&
1597 (cur_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) &&
1598 s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 2) {
1599 ffurl_closep(&s->hd);
1603 if (s->http_code < 400)
1605 ret = ff_http_averror(s->http_code, AVERROR(EIO));
1608 http_proxy_close(h);
1612 static int http_proxy_write(URLContext *h, const uint8_t *buf, int size)
1614 HTTPContext *s = h->priv_data;
1615 return ffurl_write(s->hd, buf, size);
1618 URLProtocol ff_httpproxy_protocol = {
1619 .name = "httpproxy",
1620 .url_open = http_proxy_open,
1621 .url_read = http_buf_read,
1622 .url_write = http_proxy_write,
1623 .url_close = http_proxy_close,
1624 .url_get_file_handle = http_get_file_handle,
1625 .priv_data_size = sizeof(HTTPContext),
1626 .flags = URL_PROTOCOL_FLAG_NETWORK,
1628 #endif /* CONFIG_HTTPPROXY_PROTOCOL */