This commit is contained in:
Aleric Inglewood
2012-08-06 23:19:09 +02:00
parent f479ea4bcf
commit 95083e846b
2 changed files with 60 additions and 51 deletions

View File

@@ -256,7 +256,13 @@ static void request(
lldebugs << LLURLRequest::actionAsVerb(method) << " " << url << " " << headers << llendl; lldebugs << LLURLRequest::actionAsVerb(method) << " " << url << " " << headers << llendl;
// Insert custom headers if the caller sent any // Insert custom headers if the caller sent any.
std::vector<std::string> headers_vector;
bool has_content_type = false;
bool has_accept = false;
// Note that headers always is a map, unless no argument was passed.
if (headers.isMap()) if (headers.isMap())
{ {
if (headers.has("Cookie")) if (headers.has("Cookie"))
@@ -265,37 +271,42 @@ static void request(
} }
LLSD::map_const_iterator iter = headers.beginMap(); LLSD::map_const_iterator iter = headers.beginMap();
LLSD::map_const_iterator end = headers.endMap(); LLSD::map_const_iterator const end = headers.endMap();
for (; iter != end; ++iter) for (; iter != end; ++iter)
{ {
std::ostringstream header; // If the header is "Pragma" with no value, the caller intends to
//if the header is "Pragma" with no value // force libcurl to drop the Pragma header it so gratuitously inserts.
//the caller intends to force libcurl to drop // Before inserting the header, force libcurl to not use the proxy.
//the Pragma header it so gratuitously inserts if (iter->first.compare("Pragma") == 0 && iter->second.asString().empty())
//Before inserting the header, force libcurl
//to not use the proxy (read: llurlrequest.cpp)
static const std::string PRAGMA("Pragma");
if ((iter->first == PRAGMA) && (iter->second.asString().empty()))
{ {
req->useProxy(false); req->useProxy(false);
} }
if (iter->first.compare("Content-Type") == 0)
{
has_content_type = true;
}
if (iter->first.compare("Accept") == 0)
{
has_accept = true;
}
std::ostringstream header;
header << iter->first << ": " << iter->second.asString(); header << iter->first << ": " << iter->second.asString();
lldebugs << "header = " << header.str() << llendl; headers_vector.push_back(header.str());
req->addHeader(header.str().c_str()); }
} }
if (method == LLURLRequest::HTTP_PUT || method == LLURLRequest::HTTP_POST) if (method == LLURLRequest::HTTP_PUT || method == LLURLRequest::HTTP_POST)
{ {
static std::string const CONTENT_TYPE("Content-Type"); if (!has_content_type)
if(!headers.has(CONTENT_TYPE))
{ {
// If the Content-Type header was passed in, it has // If the Content-Type header was passed in, it has
// already been added as a header through req->addHeader // already been added as a header through req->addHeader
// in the loop above. We defer to the caller's wisdom, but // in the loop above. We defer to the caller's wisdom, but
// if they did not specify a Content-Type, then ask the // if they did not specify a Content-Type, then ask the
// injector. // injector.
req->addHeader(llformat("Content-Type: %s", body_injector->contentType()).c_str()); headers_vector.push_back(llformat("Content-Type: %s", body_injector->contentType()));
} }
} }
else else
@@ -303,21 +314,19 @@ static void request(
// Check to see if we have already set Accept or not. If no one // Check to see if we have already set Accept or not. If no one
// set it, set it to application/llsd+xml since that's what we // set it, set it to application/llsd+xml since that's what we
// almost always want. // almost always want.
static std::string const ACCEPT("Accept"); if (!has_accept)
if (!headers.has(ACCEPT))
{ {
req->addHeader("Accept: application/llsd+xml"); headers_vector.push_back("Accept: application/llsd+xml");
} }
} }
}
if (method == LLURLRequest::HTTP_POST && gMessageSystem) if (method == LLURLRequest::HTTP_POST && gMessageSystem)
{ {
req->addHeader(llformat("X-SecondLife-UDP-Listen-Port: %d", gMessageSystem->mPort).c_str()); headers_vector.push_back(llformat("X-SecondLife-UDP-Listen-Port: %d", gMessageSystem->mPort));
} }
if (method == LLURLRequest::HTTP_PUT || method == LLURLRequest::HTTP_POST) if (method == LLURLRequest::HTTP_PUT || method == LLURLRequest::HTTP_POST)
{ {
//AIFIXME:
chain.push_back(LLIOPipe::ptr_t(body_injector)); chain.push_back(LLIOPipe::ptr_t(body_injector));
} }
@@ -325,7 +334,7 @@ static void request(
AICurlEasyRequest_wat buffered_easy_request_w(*req->mCurlEasyRequest); AICurlEasyRequest_wat buffered_easy_request_w(*req->mCurlEasyRequest);
AICurlResponderBuffer_wat buffer_w(*req->mCurlEasyRequest); AICurlResponderBuffer_wat buffer_w(*req->mCurlEasyRequest);
buffer_w->prepRequest(buffered_easy_request_w, headers, responder); buffer_w->prepRequest(buffered_easy_request_w, headers_vector, responder);
req->setRequestTimeOut(timeout); req->setRequestTimeOut(timeout);
//AIFIXME: theClientPump->addChain(chain, timeout); //AIFIXME: theClientPump->addChain(chain, timeout);

View File

@@ -644,7 +644,7 @@ bool LLAppViewer::init()
mAlloc.setProfilingEnabled(gSavedSettings.getBOOL("MemProfiling")); mAlloc.setProfilingEnabled(gSavedSettings.getBOOL("MemProfiling"));
AIStateMachine::setMaxCount(gSavedSettings.getU32("StateMachineMaxTime")); AIStateMachine::setMaxCount(gSavedSettings.getU32("StateMachineMaxTime"));
AICurlEasyRequestStateMachine::setCurlRequestTimeOut(gSavedSettings.getF32("CurlRequestTimeOut")); AICurlEasyRequestStateMachine::setDefaultRequestTimeOut(gSavedSettings.getF32("CurlRequestTimeOut"));
initThreads(); initThreads();
LL_INFOS("InitInfo") << "Threads initialized." << LL_ENDL ; LL_INFOS("InitInfo") << "Threads initialized." << LL_ENDL ;