diff options
Diffstat (limited to 'src/DownloadUtils.cpp')
-rw-r--r-- | src/DownloadUtils.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp index afef072..7660cee 100644 --- a/src/DownloadUtils.cpp +++ b/src/DownloadUtils.cpp @@ -29,13 +29,11 @@ namespace QuickMedia { return 0; } - static bool http_is_redirect(const std::string &header, size_t size) { - size_t end_of_first_line = header.find("\r\n"); - if(end_of_first_line == std::string::npos) + static bool http_is_redirect(const char *header, size_t size) { + const void *end_of_first_line_p = memmem(header, size, "\r\n", 2); + if(!end_of_first_line_p) return false; - - size_t find_index = header.find(" 30"); - return find_index != std::string::npos && find_index < size; + return memmem(header, (const char*)end_of_first_line_p - header, " 30", 3) != nullptr; } static int accumulate_string_with_header(char *data, int size, void *userdata) { @@ -49,7 +47,7 @@ namespace QuickMedia { size_t end_of_headers_index = download_userdata->header->find("\r\n\r\n"); if(end_of_headers_index != std::string::npos) { while(true) { - const bool is_redirect = http_is_redirect(*download_userdata->header, end_of_headers_index); + const bool is_redirect = http_is_redirect(download_userdata->header->c_str(), end_of_headers_index); end_of_headers_index += 4; if(is_redirect && download_userdata->header->size() - end_of_headers_index > 0) { download_userdata->header->erase(download_userdata->header->begin(), download_userdata->header->begin() + end_of_headers_index); |