Commit Graph

390 Commits

Author SHA1 Message Date
Limin Wang
3b8b6d837e avformat/http: Fix for invalid use of av_strtok
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-10 22:32:34 +08:00
Marton Balint
6a7b5226e1 avformat/http: escape unsafe URL path in HTTP request
This avoids generating invalid HTTP requests if the path contains space or
other special characters.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-15 18:41:36 +01:00
Marton Balint
86b2fe9411 avformat/http: use AVBPrint to construct HTTP request
v2: Use s->buffer for creating request (as the old code did) instead of
the AVBPrint internal buffer. Some minor cosmetics.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-15 18:41:36 +01:00
Marton Balint
a3d8875df1 avformat/http: make sure URL path contains a slash
It is explicitly required by the HTTP RFC. Without this patch URLs like
http://example.com?query will not work.

Fixes ticket #8466.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-15 18:41:36 +01:00
Marton Balint
987ce96d41 avformat/http: split the fragment part from the HTTP URL before the request
RFC 3986 states that the fragment identifier is separated from the rest of the
URI prior to a dereference, and thus the identifying information within the
fragment itself is dereferenced solely by the user agent.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-15 18:41:36 +01:00
Steven Liu
b9606064c4 avformat/hls: support data protocol in uri for EXT-X-MAP
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-01-18 22:41:11 +08:00
vectronic
e81c686a95 avformat/http: add ff_http_do_new_request2 for options
add ff_http_do_new_request2() which supports options to be applied to
HTTPContext after initialisation with the new uri

Signed-off-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: vectronic <hello.vectronic@gmail.com>
2019-10-08 14:57:44 +08:00
Steven Liu
6c593fee63 avformat/http: add ff_http_get_shutdown_status api for check the status of shutdown
this function is used to get the previous shutdown status
when reusing the old connection in block mode.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-09-06 10:26:16 +08:00
Steven Liu
1b1b974aac avformat/http: change error message from numeric code to string
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-07-11 09:35:31 +08:00
Jun Li
4f5e660e69 avformat/doc, http, icecast, rtsp: Add option to disable send-expect-100
Fix ticket #7297
The current setting for send-expect-100 option is either
enabled if applicable or forced enabled, no option to force
disable the header. This change is to expand the option setting
to provide more flexibility, which is useful for rstp case.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-03-31 23:23:52 +02:00
Carl Eugen Hoyos
7be245498b lavf/http: Print metadata updates with -loglevel verbose.
Simplifies metadata debugging.
2019-03-20 17:43:19 +01:00
Justin Ruggles
69fcc093c1 http: Do not try to make a new request when seeking past the end of the file
This avoids making invalid HTTP Range requests for a byte range past the
known end of the file during a seek. Those requests generally return a HTTP
response of 416 Range Not Satisfiable, which causes an error response.

Reference: https://tools.ietf.org/html/rfc7233

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2019-02-26 14:48:27 -05:00
Wenxiang Qian
85f91ed760 avformat/http: Fix Out-of-Bounds access in process_line()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-17 10:29:42 +01:00
Gyan Doshi
2e2b44baba avformat/http: clarify that ffmpeg will attempt to add missing CRLF 2019-01-29 09:58:30 +05:30
kjeyapal@akamai.com
ce0a753634 avformat/http : Added check for valid URL context before calling shutdown 2018-11-22 12:06:27 +05:30
Clément Bœsch
2e341eb15b lavf/http: use AV_OPT_FLAG_DEPRECATED for user-agent option 2018-04-26 19:50:29 +02:00
Vishwanath Dixit
30940be359 avformat/http: flushing tcp receive buffer when it is write only mode
In write only mode, the TCP receive buffer's data keeps growing with
http response messages and the buffer eventually becomes full.
This results in zero tcp window size, which in turn causes unwanted
issues, like, terminated tcp connection. The issue is apparent when
http persistent connection is enabled in hls/dash live streaming use
cases. To overcome this issue, the logic here reads the buffer data
when a file transfer is completed, so that any accumulated data in
the recieve buffer gets flushed out.
2018-04-20 11:31:21 +05:30
Stephan Holljes
7b6b8c9265 lavf/http.c: Free allocated client URLContext in case of error.
Signed-off-by: Stephan Holljes <klaxa1337@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-20 01:46:32 +02:00
Richard Shaffer
c705476c47 libavformat/http: Refactor and fix additional leaks in get_cookies.
This refactors get_cookies to simplify some code paths, specifically for
skipping logic in the while loop or exiting it. It also simplifies the logic
for appending additional values to *cookies by replacing strlen/malloc/snprintf
with one call av_asnprintf.

This refactor fixes a bug where the cookie_params AVDictionary would get leaked
if we failed to allocate a new buffer for writing to *cookies.
2018-04-19 22:01:51 +02:00
Richard Shaffer
9a8811f478 libavformat/http: Fix memory leak in get_cookies. 2018-04-17 22:00:54 +02:00
wm4
b7d842c554 http: fix potentially dangerous whitespace skipping code
If the string consists entirely of whitespace, this could in theory
continue to write '\0' before the start of the memory allocation. In
practice, it didn't really happen: the generic HTTP header parsing code
already skips leading whitespaces, so the string is either empty, or
consists a non-whitespace. (The generic code and the cookie code
actually have different ideas about what bytes are whitespace: the
former uses av_isspace(), the latter uses WHITESPACES. Fortunately,
av_isspace() is a super set of the http.c specific WHITESPACES, so
there's probably no case where the above assumption could have been
broken.)
2018-03-18 12:36:24 +01:00
wm4
c0687acbf6 http: avoid out of bound accesses on broken Set-Cookie headers
It's trivial to craft a HTTP response that will make the code for
skipping trailing whitespace access and possibly overwrite bytes outside
of the memory allocation. Why this can happen is blindingly obvious: it
accesses cstr[strlen(cstr)-1] without checking whether the string is
empty.
2018-03-18 12:36:24 +01:00
wm4
39c1d170a3 http: do not print a warning message for expired cookies
libavformat prints a warning that the cookie couldn't be parsed (see
callers of parse_cookie()). This is obviously not true - it could be
parsed, but was simply ignored. Don't return an error to avoid the
warning.
2018-03-18 12:36:24 +01:00
Steven Liu
44f3430674 avformat/http: add referer option into http
add Referer message if referer have been set.
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2018-02-01 10:56:51 +08:00
wm4
43e1ccfea1 http: cosmetics: reformat reconnect check for better readability
The condition was a bit too long, and most editors will break the line
and turn it into an unreadable mess. Move out some of the conditions.

This should not change the behavior.
2018-01-15 12:37:30 +01:00
Richard Shaffer
9147c09755 avformat/http: fix memory leak in parse_cookie.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-01-12 12:31:55 +01:00
wm4
2477bfe221 http: avoid logging reconnect warning if stream was aborted
If the stream was aborted using the libavformat interrupt callback, we
don't want it to log the reconnect warning. (Exiting after logging this
warning worked well, so this is only for avoiding the ugly warning.)
2018-01-04 18:08:31 +01:00
wm4
1b283c4a0d http: bump message level for reconnect message and log timeout 2018-01-04 15:07:55 +01:00
wm4
8a108bdea0 http: block while waiting for reconnecting
It makes no sense to return an error after the first reconnect, and then
somehow resume the next time it's called. Usually this will lead to
demuxer errors. Make reconnecting block instead, until it has either
successfully reconnected, or given up.

Also make the wait reasonably interruptible. Since there is no mechanism
for this in the API, polling is the best we can do. This behaves roughly
the same as other interruptible network functions in libavformat.

(The original code would work if it returned AVERROR(EAGAIN) or so,
which would make retry_transfer_wrapper() repeat the read call. But I
think having an explicit loop for this is better anyway.)

I also snuck in a fix for reconnect_at_eof. It has to check for
AVERROR_EOF, not 0.
2018-01-04 15:07:55 +01:00
Aman Gupta
c0b08ef94f avformat/http: return EINVAL if ff_http_do_new_request is called with non-http URLContext
Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-12-30 09:58:03 -08:00
Aman Gupta
039007c928 avformat/http: export http_version from response
Can be used by the api user to figure out what http features the server supports based on the response received.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-12-26 14:52:36 -08:00
Aman Gupta
11f989945e avformat/http: avoid ff_http_do_new_request after http/1.0 response
This makes do_new_request fail early when dealing with a http/1.0 server, avoiding unnecessary "reconnecting" warnings shown to the user.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-12-26 14:48:14 -08:00
Karthick Jeyapal
6848201f70 avformat/http: Avoid calling http_shutdown() if end of chunk is signalled already 2017-12-25 12:07:43 +08:00
Aman Gupta
54d0ef1738 avformat/http: return EOF from ff_http_do_new_request if previous response said Connection:close
This fixes a deadlock when using the hls demuxer's new http_persistent feature
to stream a youtube live stream over HTTPS. The youtube servers are http/1.1
compliant, but return a "Connecton: close". Before this commit, the demuxer
would attempt to send a new request on the partially shutdown connection and
cause a deadlock in the tls protocol.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-12-22 16:39:37 -08:00
Aman Gupta
9395e44b8d avformat/http: add "Opening" info logging to ff_http_do_new_request
This mimics logging that was added in 53e0d5d724 for security
purposes.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-22 14:42:50 -08:00
Aman Gupta
28358e466d avformat/http: return EINVAL from ff_http_do_new_request() if re-used with different hostname
This will prevent improper use of ff_http_do_new_request() if the user
tries to send a request for a different host to a previously connected
persistent http/1.1 connection.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Karthick J <kjeyapal@akamai.com>
2017-12-22 14:42:35 -08:00
Jeyapal, Karthick
4ddf7476c0 libavformat/http: Handled multiple_requests option during write 2017-11-29 14:32:16 +08:00
Aman Gupta
91a565e20f avformat/http: fix chunked response w/ multiple_requests=1
Currently if you use the multiple_requests=1 option and try to
receive a chunked-encoded response, http_buf_read() will hang forever.

After this patch, EOF is emulated once a 0-byte final chunk is
received by setting a new flag. This flag is reset in ff_http_do_new_request(),
which is used to make additional requests on the open socket.

Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-11-14 07:36:51 -08:00
Aman Gupta
52bf0febb3 avformat/http: fix stray quote in trace logging
Signed-off-by: Aman Gupta <aman@tmm1.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-13 11:19:25 -08:00
Daniel Kucera
858db4b01f libavformat: not treat 0 as EOF
transfer_func variable passed to retry_transfer_wrapper
are h->prot->url_read and h->prot->url_write functions.
These need to return EOF or other error properly.
In case of returning >= 0, url_read/url_write is retried
until error is returned.

Signed-off-by: Daniel Kucera <daniel.kucera@gmail.com>
2017-10-19 22:07:21 +02:00
Clément Bœsch
6743351558 lavf/http: fix compilation without zlib
Regression since e2f8f14052.
2017-09-15 15:10:49 +02:00
Jacek Jendrzej
e2f8f14052 lavf/http: Reset compressed header flag, fix http 302 request
Fixes ticket #6404.
Fixes ticket #6666.

Signed-off-by: Jacek Jendrzej <satbaby@kawaii.com>
2017-09-15 13:33:23 +02:00
raymondzheng
9f20cc5c84 libavformat/http: return EIO when ffurl_read return 0, but s->off < target_end
Approved-by: "Ronald S. Bultje" <rsbultje@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-09 13:27:44 +02:00
Micah Galizia
28b2467074 libavformat/http: Ignore expired cookies
Signed-off-by: Micah Galizia <micahgalizia@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-01 17:55:22 +02:00
Joel Cunningham
8c8e5d5286 HTTP: improve performance by reducing forward seeks
This commit optimizes HTTP performance by reducing forward seeks, instead
favoring a read-ahead and discard on the current connection (referred to
as a short seek) for seeks that are within a TCP window's worth of data.
This improves performance because with TCP flow control, a window's worth
of data will be in the local socket buffer already or in-flight from the
sender once congestion control on the sender is fully utilizing the window.

Note: this approach doesn't attempt to differentiate from a newly opened
connection which may not be fully utilizing the window due to congestion
control vs one that is. The receiver can't get at this information, so we
assume worst case; that full window is in use (we did advertise it after all)
and that data could be in-flight

The previous behavior of closing the connection, then opening a new
with a new HTTP range value results in a massive amounts of discarded
and re-sent data when large TCP windows are used.  This has been observed
on MacOS/iOS which starts with an initial window of 256KB and grows up to
1MB depending on the bandwidth-product delay.

When seeking within a window's worth of data and we close the connection,
then open a new one within the same window's worth of data, we discard
from the current offset till the end of the window.  Then on the new
connection the server ends up re-sending the previous data from new
offset till the end of old window.

Example (assumes full window utilization):

TCP window size: 64KB
Position: 32KB
Forward seek position: 40KB

      *                      (Next window)
32KB |--------------| 96KB |---------------| 160KB
        *
  40KB |---------------| 104KB

Re-sent amount: 96KB - 40KB = 56KB

For a real world test example, I have MP4 file of ~25MB, which ffplay
only reads ~16MB and performs 177 seeks. With current ffmpeg, this results
in 177 HTTP GETs and ~73MB worth of TCP data communication.  With this
patch, ffmpeg issues 4 HTTP GETs and 3 seeks for a total of ~22MB of TCP data
communication.

To support this feature, the short seek logic in avio_seek() has been
extended to call a function to get the short seek threshold value.  This
callback has been plumbed to the URLProtocol structure, which now has
infrastructure in HTTP and TCP to get the underlying receiver window size
via SO_RCVBUF.  If the underlying URL and protocol don't support returning
a short seek threshold, the default s->short_seek_threshold is used

This feature has been tested on Windows 7 and MacOS/iOS.  Windows support
is slightly complicated by the fact that when TCP window auto-tuning is
enabled, SO_RCVBUF doesn't report the real window size, but it does if
SO_RCVBUF was manually set (disabling auto-tuning). So we can only use
this optimization on Windows in the later case

Signed-off-by: Joel Cunningham <joel.cunningham@me.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-02-14 17:00:30 +01:00
Michael Niedermayer
8fa18e042a avformat/http: Check for truncated buffers in http_connect()
Reported-by: SleepProgger <security@gnutp.com>
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-02-14 04:02:51 +01:00
Ronald S. Bultje
845bb40178 http: move chunk handling from http_read_stream() to http_buf_read(). 2016-12-05 16:15:10 -05:00
Ronald S. Bultje
2a05c8f813 http: make length/offset-related variables unsigned.
Fixes #5992, reported and found by Paul Cher <paulcher@icloud.com>.
2016-12-05 16:15:10 -05:00
Michael Niedermayer
a880923170 avformat/http: Fix #ifdef FF_API_HTTP_USER_AGENT
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-09-17 20:14:10 +02:00
Steven Liu
27714b462d lavf/http: deprecate user-agent option 2016-09-17 13:48:34 +02:00