Index: src/plugin/PluginWbPassThrough.cpp |
diff --git a/src/plugin/PluginWbPassThrough.cpp b/src/plugin/PluginWbPassThrough.cpp |
index 9069adf80a833d0bde42587ce55df2b2b75e0065..24d9c9fecdb197414f58877110e6f82544567142 100644 |
--- a/src/plugin/PluginWbPassThrough.cpp |
+++ b/src/plugin/PluginWbPassThrough.cpp |
@@ -87,6 +87,40 @@ namespace |
auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders, L"X-Requested-With:", L"\n"); |
return TrimString(requestedWithHeader) == L"XMLHttpRequest"; |
} |
+ |
+ int GetContentTypeFromString(const std::wstring& value) |
+ { |
+ auto lastDotIt = std::find(value.rbegin(), value.rend(), L'.').base(); |
Eric
2015/02/02 18:41:58
It's much clearer just to call 'rfind':
auto
sergei
2015/02/12 14:44:06
Good point!
fixed
|
+ if (lastDotIt == value.end()) |
+ return CFilter::contentTypeAny; |
+ |
+ std::wstring ext(lastDotIt, value.end()); |
+ if (ext == L"jpg" || ext == L"gif" || ext == L"png" || ext == L"jpeg") |
+ { |
+ return CFilter::contentTypeImage; |
+ } |
+ else if (ext == L"css") |
+ { |
+ return CFilter::contentTypeStyleSheet; |
+ } |
+ else if (ext == L"js") |
+ { |
+ return CFilter::contentTypeScript; |
+ } |
+ else if (ext == L"xml") |
+ { |
+ return CFilter::contentTypeXmlHttpRequest; |
+ } |
+ else if (ext == L"swf") |
+ { |
+ return CFilter::contentTypeObject; |
+ } |
+ else if (ext == L"jsp" || ext == L"php" || ext == L"html") |
+ { |
+ return CFilter::contentTypeSubdocument; |
+ } |
+ return CFilter::contentTypeAny; |
+ } |
} |
WBPassthruSink::WBPassthruSink() |
@@ -129,44 +163,39 @@ int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
int WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) |
{ |
- CString srcLegacy = ToCString(src); |
- CString srcExt = srcLegacy; |
- |
- int pos = 0; |
- if ((pos = srcLegacy.Find('?')) > 0) |
- { |
- srcExt = srcLegacy.Left(pos); |
- } |
- |
- int lastDotIndex = srcExt.ReverseFind('.'); |
- if (lastDotIndex < 0) |
- return CFilter::contentTypeAny; |
- CString ext = srcExt.Mid(lastDotIndex); |
- if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") |
- { |
- return CFilter::contentTypeImage; |
- } |
- else if (ext == L".css") |
- { |
- return CFilter::contentTypeStyleSheet; |
- } |
- else if (ext.Right(3) == L".js") |
- { |
- return CFilter::contentTypeScript; |
- } |
- else if (ext == L".xml") |
+ // http://en.wikipedia.org/wiki/URI_scheme |
+ auto schemeAndHierarchicalPartEndsAt = src.find(L'?'); |
+ if (schemeAndHierarchicalPartEndsAt == std::wstring::npos) |
{ |
- return CFilter::contentTypeXmlHttpRequest; |
+ schemeAndHierarchicalPartEndsAt = src.find(L'#'); |
} |
- else if (ext == L".swf") |
+ std::wstring schemeAndHierarchicalPart = src.substr(0, schemeAndHierarchicalPartEndsAt); |
+ auto contentType = GetContentTypeFromString(schemeAndHierarchicalPart); |
+ if (contentType != CFilter::contentTypeAny) |
{ |
Eric
2015/02/02 18:41:58
As it's already been mentioned in the comments, it
sergei
2015/02/12 14:44:06
Actually, I'm not sure that it's a problem of only
|
- return CFilter::contentTypeObject; |
+ return contentType; |
} |
- else if (ext == L".jsp" || ext == L".php" || ext == L".html") |
- { |
- return CFilter::contentTypeSubdocument; |
- } |
- return CFilter::contentTypeAny; |
+ |
+ ProcessQueryStringParameters(GetQueryString(src), |
+ [&contentType](const std::wstring& name, const std::wstring& value)->bool |
+ { |
+ if (!value.empty()) |
+ { |
+ contentType = GetContentTypeFromString(value); |
+ if (contentType != CFilter::contentTypeAny) |
+ { |
+ return false; |
+ } |
+ } |
+ contentType = GetContentTypeFromString(name); |
+ if (contentType != CFilter::contentTypeAny) |
+ { |
+ return false; |
+ } |
+ return true; |
+ }); |
+ |
+ return contentType; |
} |
int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& domain, const std::wstring& src) |