Przeglądaj źródła

Bug 1507: Sending Content-Type header with WebDAV uploads

https://winscp.net/tracker/1507

Source commit: 163844256df0ef05a68917b7c3b262aaf5a0a489
Martin Prikryl 8 lat temu
rodzic
commit
302715baf4
2 zmienionych plików z 19 dodań i 1 usunięć
  1. 18 1
      source/core/WebDAVFileSystem.cpp
  2. 1 0
      source/core/WebDAVFileSystem.h

+ 18 - 1
source/core/WebDAVFileSystem.cpp

@@ -1514,6 +1514,17 @@ void __fastcall TWebDAVFileSystem::Source(const UnicodeString FileName,
       // (not really true as we do not support changing file name on overwrite dialog)
       Action.Destination(DestFullName);
 
+      wchar_t * MimeOut = NULL;
+      if (FindMimeFromData(NULL, DestFileName.c_str(), NULL, 0, NULL, FMFD_URLASFILENAME, &MimeOut, 0) == S_OK)
+      {
+        FUploadMimeType = MimeOut;
+        CoTaskMemFree(MimeOut);
+      }
+      else
+      {
+        FUploadMimeType = L"";
+      }
+
       FILE_OPERATION_LOOP_BEGIN
       {
         SetFilePointer(File, 0, NULL, FILE_BEGIN);
@@ -1843,6 +1854,7 @@ void TWebDAVFileSystem::NeonPreSend(
     ne_buffer_zappend(Header, "Translate: f\r\n");
   }
 
+  const UnicodeString ContentTypeHeaderPrefix(L"Content-Type: ");
   if (FileSystem->FTerminal->Log->Logging)
   {
     const char * Buffer;
@@ -1851,7 +1863,7 @@ void TWebDAVFileSystem::NeonPreSend(
     {
       // all neon request types that use ne_add_request_header
       // use XML content-type, so it's text-based
-      DebugAssert(ContainsStr(HeaderBuf, L"Content-Type: " NE_XML_MEDIA_TYPE));
+      DebugAssert(ContainsStr(HeaderBuf, ContentTypeHeaderPrefix + NE_XML_MEDIA_TYPE));
       FileSystem->FTerminal->Log->Add(llInput, UnicodeString(UTF8String(Buffer, Size)));
     }
   }
@@ -1860,6 +1872,11 @@ void TWebDAVFileSystem::NeonPreSend(
   {
     ne_set_request_body_provider_pre(Request,
       FileSystem->NeonUploadBodyProvider, FileSystem);
+    if (!FileSystem->FUploadMimeType.IsEmpty())
+    {
+      UnicodeString ContentTypeHeader = ContentTypeHeaderPrefix + FileSystem->FUploadMimeType + L"\r\n";
+      ne_buffer_zappend(Header, AnsiString(ContentTypeHeader).c_str());
+    }
   }
 
   FileSystem->FResponse = L"";

+ 1 - 0
source/core/WebDAVFileSystem.h

@@ -163,6 +163,7 @@ private:
   bool FStoredPasswordTried;
   bool FUploading;
   bool FDownloading;
+  UnicodeString FUploadMimeType;
   ne_session_s * FNeonSession;
   ne_lock_store_s * FNeonLockStore;
   TCriticalSection * FNeonLockStoreSection;