Add ResponderHeadersOnly.

ResponderHeadersOnly is a base class for responders that use
HTTPClient::head or HTTPClient::getHeaderOnly. It already
has a needsHeaders() that return true and only allows for
completedHeaders to be overridden.

I removed the CURLOPT_HEADER option for these cases, because
that only causes the headers to be send to the writeCallback
as if they are part of the body, in addition to the headerCallback;
That gave raise to some confusion for the existing code (ie,
unexpected errors when trying to decode the body as LLSD and
duplicated 'low speed' information for the Timeout policy code.
This commit is contained in:
Aleric Inglewood
2012-11-13 21:46:35 +01:00
parent 586d8fdf21
commit 6f8ea87c46
6 changed files with 71 additions and 37 deletions

View File

@@ -53,7 +53,7 @@ static LLFloaterURLEntry* sInstance = NULL;
// Move this to its own file.
// helper class that tries to download a URL from a web site and calls a method
// on the Panel Land Media and to discover the MIME type
class LLMediaTypeResponder : public LLHTTPClient::ResponderIgnoreBody
class LLMediaTypeResponder : public LLHTTPClient::ResponderHeadersOnly
{
public:
LLMediaTypeResponder( const LLHandle<LLFloater> parent ) :
@@ -62,20 +62,20 @@ public:
LLHandle<LLFloater> mParent;
virtual bool needsHeaders(void) const { return true; }
virtual void completedHeaders(U32 status, std::string const& reason, AIHTTPReceivedHeaders const& headers)
{
std::string media_type;
bool content_type_found = headers.getFirstValue("content-type", media_type);
llassert_always(content_type_found);
std::string::size_type idx1 = media_type.find_first_of(";");
std::string mime_type = media_type.substr(0, idx1);
completeAny(status, mime_type);
}
virtual void error( U32 status, const std::string& reason )
{
if (200 <= status && status < 300)
{
std::string media_type;
if (headers.getFirstValue("content-type", media_type))
{
std::string::size_type idx1 = media_type.find_first_of(";");
std::string mime_type = media_type.substr(0, idx1);
completeAny(status, mime_type);
return;
}
llwarns << "LLMediaTypeResponder::completedHeaders: OK HTTP status (" << status << ") but no Content-Type! Received headers: " << headers << llendl;
}
completeAny(status, "none/none");
}