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.
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().
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
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
Looks like a good fix, will test and apply if it works here, thanks.
Did it work ?
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; }