Bug 55973 - Incorrect mimetypes for css and other fileformats.
Summary: Incorrect mimetypes for css and other fileformats.
Status: RESOLVED FIXED
Alias: None
Product: kpf
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: rik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-15 01:14 UTC by Mikael Andersson
Modified: 2004-03-26 13:38 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Proposed patch using new mimetype detection scheme. (1.39 KB, patch)
2003-03-15 01:23 UTC, Mikael Andersson
Details
Testcase (487 bytes, application/x-tgz)
2003-04-09 02:34 UTC, Mikael Andersson
Details
Testcase (487 bytes, application/x-tgz)
2003-04-09 02:35 UTC, Mikael Andersson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mikael Andersson 2003-03-15 01:14:12 UTC
Version:            (using KDE KDE 3.1)
Installed from:    Compiled From Sources
OS:          Linux

kpf (incorrectly?) uses kmimemagic instead of kmimetype to determine mimetype of served documents. This leads to css stylesheets served as text/plain or text/csrs instead of the expected text/css depending on their content.
Comment 1 Mikael Andersson 2003-03-15 01:23:38 UTC
Created attachment 1184 [details]
Proposed patch using new mimetype detection scheme.

diff against KDE_3_1_0_RELEASE which atm is same as HEAD.
The strategy is to use KMimeType::findByPath with fallback to content analysis
through KMimeType::findByFileContent for files which findByPath fail to resolve
to anything different than defaultMimeType().
Comment 2 Mikael Andersson 2003-04-09 02:34:23 UTC
Created attachment 1329 [details]
Testcase

To verify bug unpack simple.tgz and place in kpf public_html directory. Try
accessing simple.html with:
a) konqueror ( It works and the backround is red because it ignores the
content-type)
b) phoenix/mozilla (doesn't work since mozilla cares about the content type
of the stylesheet)

In this particular case kpf sends the mime type text/x-csrc, but i've managed
to produce both text/plain and text/x-c-c++src
/Mikael Andersson
Comment 3 Mikael Andersson 2003-04-09 02:35:07 UTC
Created attachment 1330 [details]
Testcase

To verify bug unpack simple.tgz and place in kpf public_html directory. Try
accessing simple.html with:
a) konqueror ( It works and the backround is red because it ignores the
content-type)
b) phoenix/mozilla (doesn't work since mozilla cares about the content type
of the stylesheet)

In this particular case kpf sends the mime type text/x-csrc, but i've managed
to produce both text/plain and text/x-c-c++src
/Mikael Andersson
Comment 4 rik 2003-04-09 10:19:04 UTC
Looks like a good fix, will test and apply if it works here, thanks. 
Comment 5 Mikael Andersson 2003-07-04 21:20:40 UTC
Did it work ? 
Comment 6 Waldo Bastian 2004-03-26 13:38:05 UTC
CVS commit by waba: 

Improve mimetype detection. (BR55973)
Patch by Mikael Andersson
CCMAIL: 55973-done@bugs.kde.org


  M +20 -10    Resource.cpp   1.9


--- kdenetwork/kpf/src/Resource.cpp  #1.8:1.9
@@ -29,5 +29,5 @@
 #include <kglobal.h>
 
-#include <kmimemagic.h>
+#include <kmimetype.h>
 
 #include "Utils.h"
@@ -326,14 +326,24 @@ namespace KPF
     if (d->fileInfo.isDir())
       return "text/html; charset=utf-8";
+    QString serviceType = KMimeType::findByPath( d->root + d->path )->name();
 
-    KMimeMagicResult * r = KMimeMagic::self()->findFileType(d->root + d->path);
-
-    // Send "text/plain" as the mime type of the resource if we can't
-    // get a more authoritative response from KMimeMagic.
-
-    if (0 == r)
-      return "text/plain";
-    else
-      return r->mimeType();
+   /* 
+     Look at magic numbers only if findByPath couldn't come up with something
+     reasonable. 
+    */
+    if (serviceType == KMimeType::defaultMimeType())
+    {
+        int accuracy;
+        QString contentServiceType = KMimeType::findByFileContent( d->root + d->path,&accuracy)->name();
+        /*
+          Use reliable information ( from magic number ) only. Ignore any exotic
+          matches and leave as defaultMimeType for any such hard-to-identify documents.
+        */
+        if (accuracy == 100)
+        {
+            serviceType = contentServiceType;
+        }
+    }
+    return serviceType;
   }