diff options
| author | Don Kjer <don@lindenlab.com> | 2013-05-08 05:51:28 +0000 | 
|---|---|---|
| committer | Don Kjer <don@lindenlab.com> | 2013-05-08 05:51:28 +0000 | 
| commit | 3a351c4ee548e2bce8ad0d5935377a090591621f (patch) | |
| tree | a1e0987e75e9f02071b29539a5423a94714f5366 | |
| parent | 7223f016469ecaacedb841ea435207c4266269e8 (diff) | |
Adding follow_redirects parameter to LLHTTPClient get/head variants.  Not following redirects for facebook connect requests.
| -rwxr-xr-x | indra/llmessage/llhttpclient.cpp | 35 | ||||
| -rw-r--r-- | indra/llmessage/llhttpclient.h | 19 | ||||
| -rw-r--r-- | indra/llmessage/llurlrequest.cpp | 21 | ||||
| -rw-r--r-- | indra/llmessage/llurlrequest.h | 9 | ||||
| -rw-r--r-- | indra/newview/llpanelpeople.cpp | 15 | ||||
| -rw-r--r-- | indra/newview/tests/lltranslate_test.cpp | 4 | 
6 files changed, 68 insertions, 35 deletions
| diff --git a/indra/llmessage/llhttpclient.cpp b/indra/llmessage/llhttpclient.cpp index 3561459bb4..2d16237161 100755 --- a/indra/llmessage/llhttpclient.cpp +++ b/indra/llmessage/llhttpclient.cpp @@ -217,7 +217,8 @@ static void request(  	Injector* body_injector,  	LLCurl::ResponderPtr responder,  	const F32 timeout = HTTP_REQUEST_EXPIRY_SECS, -	const LLSD& headers = LLSD() +	const LLSD& headers = LLSD(), +	bool follow_redirects = true      )  {  	if (!LLHTTPClient::hasPump()) @@ -231,7 +232,7 @@ static void request(  	}  	LLPumpIO::chain_t chain; -	LLURLRequest* req = new LLURLRequest(method, url); +	LLURLRequest* req = new LLURLRequest(method, url, follow_redirects);  	if(!req->isValid())//failed  	{  		if (responder) @@ -334,7 +335,8 @@ void LLHTTPClient::getByteRange(  	S32 bytes,  	ResponderPtr responder,  	const LLSD& hdrs, -	const F32 timeout) +	const F32 timeout, +	bool follow_redirects /* = true */)  {  	LLSD headers = hdrs;  	if(offset > 0 || bytes > 0) @@ -342,37 +344,42 @@ void LLHTTPClient::getByteRange(  		std::string range = llformat("bytes=%d-%d", offset, offset+bytes-1);  		headers["Range"] = range;  	} -    request(url,LLURLRequest::HTTP_GET, NULL, responder, timeout, headers); +    request(url,LLURLRequest::HTTP_GET, NULL, responder, timeout, headers, follow_redirects);  }  void LLHTTPClient::head(  	const std::string& url,  	ResponderPtr responder,  	const LLSD& headers, -	const F32 timeout) +	const F32 timeout, +	bool follow_redirects /* = true */)  { -	request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout, headers); +	request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout, headers, follow_redirects);  } -void LLHTTPClient::get(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout) +void LLHTTPClient::get(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout, +					   bool follow_redirects /* = true */)  { -	request(url, LLURLRequest::HTTP_GET, NULL, responder, timeout, headers); +	request(url, LLURLRequest::HTTP_GET, NULL, responder, timeout, headers, follow_redirects);  } -void LLHTTPClient::getHeaderOnly(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout) +void LLHTTPClient::getHeaderOnly(const std::string& url, ResponderPtr responder, const LLSD& headers, +								 const F32 timeout, bool follow_redirects /* = true */)  { -	request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout, headers); +	request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout, headers, follow_redirects);  } -void LLHTTPClient::getHeaderOnly(const std::string& url, ResponderPtr responder, const F32 timeout) +void LLHTTPClient::getHeaderOnly(const std::string& url, ResponderPtr responder, const F32 timeout, +								 bool follow_redirects /* = true */)  { -	getHeaderOnly(url, responder, LLSD(), timeout); +	getHeaderOnly(url, responder, LLSD(), timeout, follow_redirects);  } -void LLHTTPClient::get(const std::string& url, const LLSD& query, ResponderPtr responder, const LLSD& headers, const F32 timeout) +void LLHTTPClient::get(const std::string& url, const LLSD& query, ResponderPtr responder, const LLSD& headers, +					   const F32 timeout, bool follow_redirects /* = true */)  {  	LLURI uri;  	uri = LLURI::buildHTTP(url, LLSD::emptyArray(), query); -	get(uri.asString(), responder, headers, timeout); +	get(uri.asString(), responder, headers, timeout, follow_redirects);  }  // A simple class for managing data returned from a curl http request. diff --git a/indra/llmessage/llhttpclient.h b/indra/llmessage/llhttpclient.h index a7236ba169..5de257a4f6 100644 --- a/indra/llmessage/llhttpclient.h +++ b/indra/llmessage/llhttpclient.h @@ -63,10 +63,15 @@ public:  		const std::string& url,  		ResponderPtr,  		const LLSD& headers = LLSD(), -		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS); -	static void getByteRange(const std::string& url, S32 offset, S32 bytes, ResponderPtr, const LLSD& headers=LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS); -	static void get(const std::string& url, ResponderPtr, const LLSD& headers = LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS); -	static void get(const std::string& url, const LLSD& query, ResponderPtr, const LLSD& headers = LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS); +		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS, +		bool follow_redirects = true); +	static void getByteRange(const std::string& url, S32 offset, S32 bytes, ResponderPtr, +							 const LLSD& headers=LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS, +							 bool follow_redirects = true); +	static void get(const std::string& url, ResponderPtr, const LLSD& headers = LLSD(), +					const F32 timeout=HTTP_REQUEST_EXPIRY_SECS, bool follow_redirects = true); +	static void get(const std::string& url, const LLSD& query, ResponderPtr, const LLSD& headers = LLSD(), +					const F32 timeout=HTTP_REQUEST_EXPIRY_SECS, bool follow_redirects = true);  	static void put(  		const std::string& url, @@ -74,8 +79,10 @@ public:  		ResponderPtr,  		const LLSD& headers = LLSD(),  		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS); -	static void getHeaderOnly(const std::string& url, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS); -	static void getHeaderOnly(const std::string& url, ResponderPtr, const LLSD& headers, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS); +	static void getHeaderOnly(const std::string& url, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS, +							  bool follow_redirects = true); +	static void getHeaderOnly(const std::string& url, ResponderPtr, const LLSD& headers, +							  const F32 timeout=HTTP_REQUEST_EXPIRY_SECS, bool follow_redirects = true);  	static void post(  		const std::string& url, diff --git a/indra/llmessage/llurlrequest.cpp b/indra/llmessage/llurlrequest.cpp index 627d591839..49f8144ee7 100644 --- a/indra/llmessage/llurlrequest.cpp +++ b/indra/llmessage/llurlrequest.cpp @@ -150,16 +150,19 @@ std::string LLURLRequest::actionAsVerb(LLURLRequest::ERequestAction action)  	return VERBS[action];  } -LLURLRequest::LLURLRequest(LLURLRequest::ERequestAction action) : -	mAction(action) +LLURLRequest::LLURLRequest(LLURLRequest::ERequestAction action, bool follow_redirects /* = true */) : +	mAction(action), +	mFollowRedirects(follow_redirects)  {  	initialize();  }  LLURLRequest::LLURLRequest(  	LLURLRequest::ERequestAction action, -	const std::string& url) : -	mAction(action) +	const std::string& url, +	bool follow_redirects /* = true */) : +	mAction(action), +	mFollowRedirects(follow_redirects)  {  	initialize();  	setURL(url); @@ -479,12 +482,18 @@ bool LLURLRequest::configure()  	case HTTP_HEAD:  		mDetail->mCurlRequest->setopt(CURLOPT_HEADER, 1);  		mDetail->mCurlRequest->setopt(CURLOPT_NOBODY, 1); -		mDetail->mCurlRequest->setopt(CURLOPT_FOLLOWLOCATION, 1); +		if (mFollowRedirects) +		{ +			mDetail->mCurlRequest->setopt(CURLOPT_FOLLOWLOCATION, 1); +		}  		rv = true;  		break;  	case HTTP_GET:  		mDetail->mCurlRequest->setopt(CURLOPT_HTTPGET, 1); -		mDetail->mCurlRequest->setopt(CURLOPT_FOLLOWLOCATION, 1); +		if (mFollowRedirects) +		{ +			mDetail->mCurlRequest->setopt(CURLOPT_FOLLOWLOCATION, 1); +		}  		// Set Accept-Encoding to allow response compression  		mDetail->mCurlRequest->setoptString(CURLOPT_ENCODING, ""); diff --git a/indra/llmessage/llurlrequest.h b/indra/llmessage/llurlrequest.h index 44d358d906..20d6e30d17 100644 --- a/indra/llmessage/llurlrequest.h +++ b/indra/llmessage/llurlrequest.h @@ -95,7 +95,7 @@ public:  	 *  	 * @param action One of the ERequestAction enumerations.  	 */ -	LLURLRequest(ERequestAction action); +	LLURLRequest(ERequestAction action, bool follow_redirects = true);  	/**   	 * @brief Constructor. @@ -103,7 +103,7 @@ public:  	 * @param action One of the ERequestAction enumerations.  	 * @param url The url of the request. It should already be encoded.  	 */ -	LLURLRequest(ERequestAction action, const std::string& url); +	LLURLRequest(ERequestAction action, const std::string& url, bool follow_redirects = true);  	/**   	 * @brief Destructor. @@ -219,10 +219,11 @@ protected:  	};  	EState mState;  	ERequestAction mAction; +	bool mFollowRedirects;  	LLURLRequestDetail* mDetail;  	LLIOPipe::ptr_t mCompletionCallback; -	 S32 mRequestTransferedBytes; -	 S32 mResponseTransferedBytes; +	S32 mRequestTransferedBytes; +	S32 mResponseTransferedBytes;  	static CURLcode _sslCtxCallback(CURL * curl, void *sslctx, void *param); diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp index af9ecd743c..479e503ef0 100644 --- a/indra/newview/llpanelpeople.cpp +++ b/indra/newview/llpanelpeople.cpp @@ -1854,14 +1854,20 @@ public:  void LLPanelPeople::loadFacebookFriends()  { -	LLHTTPClient::get(getFacebookConnectURL("/friend"), new FacebookFriendsResponder(this)); +	const bool follow_redirects=false; +	const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; +	LLHTTPClient::get(getFacebookConnectURL("/friend"), new FacebookFriendsResponder(this), +					  LLSD(), timeout, follow_redirects);  }  void LLPanelPeople::tryToReconnectToFacebook()  {  	if (!mConnectedToFbc)  	{ -		LLHTTPClient::get(getFacebookConnectURL("/connection"), new FacebookConnectedResponder(this, false)); +		const bool follow_redirects=false; +		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; +		LLHTTPClient::get(getFacebookConnectURL("/connection"), new FacebookConnectedResponder(this, false), +						  LLSD(), timeout, follow_redirects);  	}  } @@ -1895,7 +1901,10 @@ void LLPanelPeople::onLoginFbcButtonClicked()  	}  	else  	{ -		LLHTTPClient::get(getFacebookConnectURL("/connection"), new FacebookConnectedResponder(this, true)); +		const bool follow_redirects=false; +		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; +		LLHTTPClient::get(getFacebookConnectURL("/connection"), new FacebookConnectedResponder(this, true), +						  LLSD(), timeout, follow_redirects);  	}  } diff --git a/indra/newview/tests/lltranslate_test.cpp b/indra/newview/tests/lltranslate_test.cpp index fd9527d631..8ce56326d8 100644 --- a/indra/newview/tests/lltranslate_test.cpp +++ b/indra/newview/tests/lltranslate_test.cpp @@ -308,8 +308,8 @@ void LLCurl::Responder::errorWithContent(U32, std::string const&, LLSD const&) {  void LLCurl::Responder::result(LLSD const&) {}  LLCurl::Responder::~Responder() {} -void LLHTTPClient::get(const std::string&, const LLSD&, ResponderPtr, const LLSD&, const F32) {} -void LLHTTPClient::get(const std::string&, LLPointer<LLCurl::Responder>, const LLSD&, const F32) {} +void LLHTTPClient::get(const std::string&, const LLSD&, ResponderPtr, const LLSD&, const F32, bool) {} +void LLHTTPClient::get(const std::string&, LLPointer<LLCurl::Responder>, const LLSD&, const F32, bool) {}  LLBufferStream::LLBufferStream(const LLChannelDescriptors& channels, LLBufferArray* buffer)  :	std::iostream(&mStreamBuf), mStreamBuf(channels, buffer) {} | 
