Fix LLMimeDiscoveryResponder.

Extract Content-Type also from a 405 reply.
If all else fails, use a default mime-type for url's opened
in the browser (start with http: or https:) of "text/html" instead
of "none/none".
This commit is contained in:
Aleric Inglewood
2012-11-18 03:29:01 +01:00
parent f44de434c2
commit 5947769812

View File

@@ -75,14 +75,15 @@ class LLMimeDiscoveryResponder : public LLHTTPClient::ResponderHeadersOnly
{
LOG_CLASS(LLMimeDiscoveryResponder);
public:
LLMimeDiscoveryResponder( viewer_media_t media_impl)
LLMimeDiscoveryResponder(viewer_media_t media_impl, std::string const& default_mime_type)
: mMediaImpl(media_impl),
mDefaultMimeType(default_mime_type),
mInitialized(false)
{}
/*virtual*/ void completedHeaders(U32 status, std::string const& reason, AIHTTPReceivedHeaders const& headers)
{
if (200 <= status && status < 300)
if (200 <= status && status < 300 || status == 405) // Using HEAD may result in a 405 METHOD NOT ALLOWED, but still have the right Content-TYpe header.
{
std::string media_type;
if (headers.getFirstValue("content-type", media_type))
@@ -92,9 +93,13 @@ public:
completeAny(status, mime_type);
return;
}
llwarns << "LLMimeDiscoveryResponder::completedHeaders: OK HTTP status (" << status << ") but no Content-Type! Received headers: " << headers << llendl;
if (200 <= status && status < 300)
{
llwarns << "LLMimeDiscoveryResponder::completedHeaders: OK HTTP status (" << status << ") but no Content-Type! Received headers: " << headers << llendl;
}
}
completeAny(status, "none/none");
llwarns << "LLMimeDiscoveryResponder::completedHeaders: Got status " << status << ". Using default mime-type: " << mDefaultMimeType << llendl;
completeAny(status, mDefaultMimeType);
}
void completeAny(U32 status, const std::string& mime_type)
@@ -113,6 +118,7 @@ public:
public:
viewer_media_t mMediaImpl;
std::string mDefaultMimeType;
bool mInitialized;
};
@@ -1313,7 +1319,7 @@ void LLViewerMediaImpl::navigateTo(const std::string& url, const std::string& mi
{
if(mime_type.empty())
{
LLHTTPClient::getHeaderOnly( url, new LLMimeDiscoveryResponder(this));
LLHTTPClient::getHeaderOnly(url, new LLMimeDiscoveryResponder(this, "text/html"));
}
else if(initializeMedia(mime_type) && (plugin = getMediaPlugin()))
{