Fix content type detection broken by commit 1b53fe9765e9fdfd56e4ddd91d87b7d04c55650a

The detection should be done in three phases instead of two:
1) in case if two types might have the same file suffix it will fail
certainity therefore we come to test file contents.
2) if that test is again uncertain it is reasonable to test both basename
and contents this time.