TEST_F(TestWebServer, CanGetCachedFileWithOlderIfUnmodifiedSince) { // get the last modified date of the file CDateTime lastModified; ASSERT_TRUE(GetLastModifiedOfTestFile(TEST_FILES_RANGES, lastModified)); CDateTime lastModifiedOlder = lastModified - CDateTimeSpan(1, 0, 0, 0); // get the file with an older If-Unmodified-Since value std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, ""); curl.SetRequestHeader(MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE, lastModifiedOlder.GetAsRFC1123DateTime()); ASSERT_FALSE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); }
TEST_F(TestWebServer, CanGetCachedFileWithExactIfUnmodifiedSince) { // get the last modified date of the file CDateTime lastModified; ASSERT_TRUE(GetLastModifiedOfTestFile(TEST_FILES_RANGES, lastModified)); // get the file with an older If-Unmodified-Since value std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, ""); curl.SetRequestHeader(MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE, lastModified.GetAsRFC1123DateTime()); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); EXPECT_STREQ(TEST_FILES_DATA_RANGES, result.c_str()); CheckRangesTestFileResponse(curl); }
TEST_F(TestWebServer, CanGetCachedFileWithExactIfModifiedSince) { // get the last modified date of the file CDateTime lastModified; ASSERT_TRUE(GetLastModifiedOfTestFile(TEST_FILES_RANGES, lastModified)); // get the file with the exact If-Modified-Since value std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, ""); curl.SetRequestHeader(MHD_HTTP_HEADER_IF_MODIFIED_SINCE, lastModified.GetAsRFC1123DateTime()); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); ASSERT_TRUE(result.empty()); CheckRangesTestFileResponse(curl, MHD_HTTP_NOT_MODIFIED, true); }
TEST_F(TestWebServer, CanGetCachedFileWithNewerIfModifiedSinceForcingNoCache) { // get the last modified date of the file CDateTime lastModified; ASSERT_TRUE(GetLastModifiedOfTestFile(TEST_FILES_RANGES, lastModified)); CDateTime lastModifiedNewer = lastModified + CDateTimeSpan(1, 0, 0, 0); // get the file with a newer If-Modified-Since value but forcing no caching std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, ""); curl.SetRequestHeader(MHD_HTTP_HEADER_IF_MODIFIED_SINCE, lastModifiedNewer.GetAsRFC1123DateTime()); curl.SetRequestHeader(MHD_HTTP_HEADER_CACHE_CONTROL, "no-cache"); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); EXPECT_STREQ(TEST_FILES_DATA_RANGES, result.c_str()); CheckRangesTestFileResponse(curl); }
int CDAVFile::Stat(const CURL& url, struct __stat64* buffer) { CCurlFile dav; std::string strRequest = "PROPFIND"; dav.SetCustomRequest(strRequest); dav.SetRequestHeader("depth", 0); return dav.Stat(url, buffer); }
TEST_F(TestWebServer, CanGetFile) { std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, ""); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_HTML), result)); ASSERT_STREQ(TEST_FILES_DATA, result.c_str()); CheckHtmlTestFileResponse(curl); }
TEST_F(TestWebServer, CanGetCachedRangedFileWithExactIfRange) { const std::string rangedFileContent = TEST_FILES_DATA_RANGES; const std::string range = "bytes=0-"; CHttpRanges ranges; ASSERT_TRUE(ranges.Parse(range, rangedFileContent.size())); // get the last modified date of the file CDateTime lastModified; ASSERT_TRUE(GetLastModifiedOfTestFile(TEST_FILES_RANGES, lastModified)); // get the whole file (but ranged) with an older If-Range value std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, range); curl.SetRequestHeader(MHD_HTTP_HEADER_IF_RANGE, lastModified.GetAsRFC1123DateTime()); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); CheckRangesTestFileResponse(curl, result, ranges); }
bool CDAVDirectory::Exists(const CURL& url) { CCurlFile dav; // Set the PROPFIND custom request else we may not find folders, depending // on the server's configuration std::string strRequest = "PROPFIND"; dav.SetCustomRequest(strRequest); dav.SetRequestHeader("depth", 0); return dav.Exists(url); }
TEST_F(TestWebServer, CanGetRangedFileRange0_2xEnd) { const std::string rangedFileContent = TEST_FILES_DATA_RANGES; const std::string range = GenerateRangeHeaderValue(0, rangedFileContent.size() * 2); CHttpRanges ranges; ASSERT_TRUE(ranges.Parse(range, rangedFileContent.size())); // get the whole file but specify a larger range std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, range); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); CheckRangesTestFileResponse(curl, result, ranges); }
TEST_F(TestWebServer, CanGetRangedFileRange0_) { const std::string rangedFileContent = TEST_FILES_DATA_RANGES; const std::string range = "bytes=0-"; CHttpRanges ranges; ASSERT_TRUE(ranges.Parse(range, rangedFileContent.size())); // get the whole file but specify the beginning of the range std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, range); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); CheckRangesTestFileResponse(curl, result, ranges); }
TEST_F(TestWebServer, CanGetRangedFileRange_Last) { const std::string rangedFileContent = TEST_FILES_DATA_RANGES; std::vector<std::string> rangedContent = StringUtils::Split(TEST_FILES_DATA_RANGES, ";"); const std::string range = StringUtils::Format("bytes=-%u", static_cast<unsigned int>(rangedContent.back().size())); CHttpRanges ranges; ASSERT_TRUE(ranges.Parse(range, rangedFileContent.size())); // get the whole file but specify a larger range std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, range); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); CheckRangesTestFileResponse(curl, result, ranges); }
TEST_F(TestWebServer, CanGetRangedFileRangeFirst_Second) { const std::string rangedFileContent = TEST_FILES_DATA_RANGES; std::vector<std::string> rangedContent = StringUtils::Split(TEST_FILES_DATA_RANGES, ";"); const std::string range = GenerateRangeHeaderValue(rangedContent.front().size() + 1, rangedContent.front().size() + 1 + rangedContent.at(2).size() - 1); CHttpRanges ranges; ASSERT_TRUE(ranges.Parse(range, rangedFileContent.size())); // get the whole file but specify a larger range std::string result; CCurlFile curl; curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, range); ASSERT_TRUE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result)); CheckRangesTestFileResponse(curl, result, ranges); }
bool CDAVDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CCurlFile dav; CURL url(strPath); CStdString strRequest = "PROPFIND"; dav.SetCustomRequest(strRequest); dav.SetMimeType("text/xml; charset=\"utf-8\""); dav.SetRequestHeader("depth", 1); dav.SetPostData( "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" " <D:propfind xmlns:D=\"DAV:\">" " <D:prop>" " <D:resourcetype/>" " <D:getcontentlength/>" " <D:getlastmodified/>" " <D:creationdate/>" " <D:displayname/>" " </D:prop>" " </D:propfind>"); if (!dav.Open(url)) { CLog::Log(LOGERROR, "%s - Unable to get dav directory (%s)", __FUNCTION__, strPath.c_str()); return false; } CStdString strResponse; dav.ReadData(strResponse); CXBMCTinyXML davResponse; davResponse.Parse(strResponse.c_str()); if (!davResponse.Parse(strResponse)) { CLog::Log(LOGERROR, "%s - Unable to process dav directory (%s)", __FUNCTION__, strPath.c_str()); dav.Close(); return false; } TiXmlNode *pChild; // Iterate over all responses for (pChild = davResponse.RootElement()->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) { if (CDAVCommon::ValueWithoutNamespace(pChild, "response")) { CFileItem item; ParseResponse(pChild->ToElement(), item); CURL url2(strPath); CURL url3(item.GetPath()); CStdString itemPath(URIUtils::AddFileToFolder(url2.GetWithoutFilename(), url3.GetFileName())); if (item.GetLabel().IsEmpty()) { CStdString name(itemPath); URIUtils::RemoveSlashAtEnd(name); CURL::Decode(name); item.SetLabel(URIUtils::GetFileName(name)); } if (item.m_bIsFolder) URIUtils::AddSlashAtEnd(itemPath); // Add back protocol options if (!url2.GetProtocolOptions().IsEmpty()) itemPath += "|" + url2.GetProtocolOptions(); item.SetPath(itemPath); if (!item.GetPath().Equals(strPath)) { CFileItemPtr pItem(new CFileItem(item)); items.Add(pItem); } } } dav.Close(); return true; }