diff options
author | Max Kellermann <max@duempel.org> | 2014-11-02 14:06:05 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-11-02 14:06:05 +0100 |
commit | 303d67aed2da79d4ddaa3a52093ed42ae9da064d (patch) | |
tree | 060580f4c17b5d30d1e78e584df03c795ce4e1d7 /src/input/plugins/CurlInputPlugin.cxx | |
parent | 575fbad254a1ce67530bf2aedc9852c89c072c3f (diff) | |
parent | 6a7f6cdacd81877276563c42fdeacad3a8deface (diff) | |
download | mpd-303d67aed2da79d4ddaa3a52093ed42ae9da064d.tar.gz mpd-303d67aed2da79d4ddaa3a52093ed42ae9da064d.tar.xz mpd-303d67aed2da79d4ddaa3a52093ed42ae9da064d.zip |
Merge tag 'v0.19.2'
Diffstat (limited to 'src/input/plugins/CurlInputPlugin.cxx')
-rw-r--r-- | src/input/plugins/CurlInputPlugin.cxx | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index 617805e2c..1e1a46108 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -109,6 +109,13 @@ struct CurlInputStream final : public AsyncInputStream { */ void FreeEasyIndirect(); + /** + * Called when a new response begins. This is used to discard + * headers from previous responses (for example authentication + * and redirects). + */ + void ResponseBoundary(); + void HeaderReceived(const char *name, std::string &&value); size_t DataReceived(const void *ptr, size_t size); @@ -598,6 +605,20 @@ CurlInputStream::~CurlInputStream() } inline void +CurlInputStream::ResponseBoundary() +{ + /* undo all effects of HeaderReceived() because the previous + response was not applicable for this stream */ + + seekable = false; + size = UNKNOWN_SIZE; + ClearMimeType(); + ClearTag(); + + // TODO: reset the IcyInputStream? +} + +inline void CurlInputStream::HeaderReceived(const char *name, std::string &&value) { if (IsSeekPending()) @@ -645,6 +666,11 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream) size *= nmemb; const char *header = (const char *)ptr; + if (size > 5 && memcmp(header, "HTTP/", 5) == 0) { + c.ResponseBoundary(); + return size; + } + const char *end = header + size; char name[64]; @@ -720,10 +746,10 @@ CurlInputStream::InitEasy(Error &error) input_curl_writefunction); curl_easy_setopt(easy, CURLOPT_WRITEDATA, this); curl_easy_setopt(easy, CURLOPT_HTTP200ALIASES, http_200_aliases); - curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(easy, CURLOPT_NETRC, 1); - curl_easy_setopt(easy, CURLOPT_MAXREDIRS, 5); - curl_easy_setopt(easy, CURLOPT_FAILONERROR, true); + curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1l); + curl_easy_setopt(easy, CURLOPT_NETRC, 1l); + curl_easy_setopt(easy, CURLOPT_MAXREDIRS, 5l); + curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1l); curl_easy_setopt(easy, CURLOPT_ERRORBUFFER, error_buffer); curl_easy_setopt(easy, CURLOPT_NOPROGRESS, 1l); curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1l); |