summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-09-01 11:30:30 +0200
committerMax Kellermann <max@musicpd.org>2017-09-01 11:30:30 +0200
commitf6b56c9317ca7be2732807091d1079a54fb3a768 (patch)
treeebb903d2447dbea3abd2276a7029e8c75af66555
parent3717fb6c8dab919b44361918c6f7c91efac2dcb3 (diff)
storage/curl: move code to IsXmlContentType()
-rw-r--r--src/storage/plugins/CurlStorage.cxx19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx
index d4177e4a3..9359de38e 100644
--- a/src/storage/plugins/CurlStorage.cxx
+++ b/src/storage/plugins/CurlStorage.cxx
@@ -247,6 +247,21 @@ ParseU64(const char *s, size_t length)
return ParseU64(std::string(s, length).c_str());
}
+gcc_pure
+static bool
+IsXmlContentType(const char *content_type) noexcept
+{
+ return strncmp(content_type, "text/xml", 8) == 0;
+}
+
+gcc_pure
+static bool
+IsXmlContentType(const std::multimap<std::string, std::string> &headers) noexcept
+{
+ auto i = headers.find("content-type");
+ return i != headers.end() && IsXmlContentType(i->second.c_str());
+}
+
/**
* A WebDAV PROPFIND request. Each "response" element will be passed
* to OnDavResponse() (to be implemented by a derived class).
@@ -308,9 +323,7 @@ private:
throw FormatRuntimeError("Status %d from WebDAV server; expected \"207 Multi-Status\"",
status);
- auto i = headers.find("content-type");
- if (i == headers.end() ||
- strncmp(i->second.c_str(), "text/xml", 8) != 0)
+ if (!IsXmlContentType(headers))
throw std::runtime_error("Unexpected Content-Type from WebDAV server");
}