Skip to content

Commit

Permalink
Fix downloads with curl
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkomandy committed Dec 3, 2022
1 parent 7723873 commit ff40d19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 19 additions & 1 deletion Source/WebKitLegacy/haiku/API/WebDownloadPrivate.cpp
Expand Up @@ -65,7 +65,6 @@ WebDownloadPrivate::WebDownloadPrivate(const ResourceRequest& request,
, m_filename("Download")
, m_mimeType()
, m_mimeTypeGuessTries(kMaxMimeTypeGuessTries)
, m_file()
, m_lastProgressReportTime(0)
{
#if USE(CURL)
Expand Down Expand Up @@ -106,6 +105,10 @@ void WebDownloadPrivate::didReceiveResponseAsync(ResourceHandle*, ResourceRespon
}

m_url = response.url().string();

#if USE(CURL)
createFile();
#endif
}

#if USE(CURL)
Expand Down Expand Up @@ -201,6 +204,10 @@ void WebDownloadPrivate::start(const BPath& path)
{
if (path.InitCheck() == B_OK)
m_path = path;

#if USE(CURL)
m_download->start();
#endif
}

void WebDownloadPrivate::hasMovedTo(const BPath& path)
Expand All @@ -225,8 +232,15 @@ void WebDownloadPrivate::handleFinished(WebCore::ResourceHandle* handle, uint32
if (m_mimeTypeGuessTries != -1 && m_mimeType.Length() > 0) {
// In last resort, use the MIME type provided
// by the response, which pass our validation
#if USE(CURL)
BNode node(m_filename);
BNodeInfo info(&node);
info.SetType(m_mimeType);
node.WriteAttrString("META:url", &m_url);
#else
BNodeInfo info(&m_file);
info.SetType(m_mimeType);
#endif
}

if (m_progressListener.IsValid()) {
Expand All @@ -244,8 +258,12 @@ void WebDownloadPrivate::createFile()
// Don't overwrite existing files
findAvailableFilename();

#if USE(CURL)
m_download->setDestination(WTF::String::fromUTF8(m_path.Path()));
#else
if (m_file.SetTo(m_path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY) == B_OK)
m_file.WriteAttrString("META:url", &m_url);
#endif

if (m_progressListener.IsValid()) {
BMessage message(B_DOWNLOAD_STARTED);
Expand Down
5 changes: 4 additions & 1 deletion Source/WebKitLegacy/haiku/API/WebDownloadPrivate.h
Expand Up @@ -66,6 +66,8 @@ class WebDownloadPrivate
public:
WebDownloadPrivate(const ResourceRequest&, WebCore::NetworkingContext*);

virtual ~WebDownloadPrivate() = default;

#if USE(CURL)
virtual void didReceiveResponse(const ResourceResponse&) override;
virtual void didReceiveDataOfLength(int) override;
Expand Down Expand Up @@ -106,6 +108,8 @@ class WebDownloadPrivate
#if USE(CURL)
RefPtr<WebCore::CurlDownload> m_download;
ResourceResponse m_response;
#else
BFile m_file;
#endif
RefPtr<ResourceHandle> m_resourceHandle;
off_t m_currentSize;
Expand All @@ -115,7 +119,6 @@ class WebDownloadPrivate
BString m_filename;
BString m_mimeType;
int m_mimeTypeGuessTries;
BFile m_file;
bigtime_t m_lastProgressReportTime;

BMessenger m_progressListener;
Expand Down

0 comments on commit ff40d19

Please sign in to comment.