diff options
Diffstat (limited to 'indra/newview/llwebprofile.cpp')
-rwxr-xr-x | indra/newview/llwebprofile.cpp | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/indra/newview/llwebprofile.cpp b/indra/newview/llwebprofile.cpp index 69255af179..ddb7f7bfce 100755 --- a/indra/newview/llwebprofile.cpp +++ b/indra/newview/llwebprofile.cpp @@ -67,9 +67,8 @@ public: { } + // *TODO: Check for 'application/json' content type, and parse json at the base class. /*virtual*/ void completedRaw( - U32 status, - const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer) { @@ -78,9 +77,9 @@ public: strstrm << istr.rdbuf(); const std::string body = strstrm.str(); - if (status != 200) + if (getStatus() != HTTP_OK) { - llwarns << "Failed to get upload config (" << status << ")" << llendl; + LL_WARNS() << "Failed to get upload config " << dumpResponse() << LL_ENDL; LLWebProfile::reportImageUploadStatus(false); return; } @@ -89,7 +88,7 @@ public: Json::Reader reader; if (!reader.parse(body, root)) { - llwarns << "Failed to parse upload config: " << reader.getFormatedErrorMessages() << llendl; + LL_WARNS() << "Failed to parse upload config: " << reader.getFormatedErrorMessages() << LL_ENDL; LLWebProfile::reportImageUploadStatus(false); return; } @@ -112,7 +111,7 @@ public: config["caption"] = data.get("caption", "").asString(); // Do the actual image upload using the configuration. - LL_DEBUGS("Snapshots") << "Got upload config, POSTing image to " << upload_url << ", config=[" << config << "]" << llendl; + LL_DEBUGS("Snapshots") << "Got upload config, POSTing image to " << upload_url << ", config=[" << config << "]" << LL_ENDL; LLWebProfile::post(mImagep, config, upload_url); } @@ -128,14 +127,12 @@ class LLWebProfileResponders::PostImageRedirectResponder : public LLHTTPClient:: public: /*virtual*/ void completedRaw( - U32 status, - const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer) { - if (status != 200) + if (getStatus() != HTTP_OK) { - llwarns << "Failed to upload image: " << status << " " << reason << llendl; + LL_WARNS() << "Failed to upload image " << dumpResponse() << LL_ENDL; LLWebProfile::reportImageUploadStatus(false); return; } @@ -144,8 +141,8 @@ public: std::stringstream strstrm; strstrm << istr.rdbuf(); const std::string body = strstrm.str(); - llinfos << "Image uploaded." << llendl; - LL_DEBUGS("Snapshots") << "Uploading image succeeded. Response: [" << body << "]" << llendl; + LL_INFOS() << "Image uploaded." << LL_ENDL; + LL_DEBUGS("Snapshots") << "Uploading image succeeded. Response: [" << body << "]" << LL_ENDL; LLWebProfile::reportImageUploadStatus(true); } }; @@ -158,33 +155,36 @@ class LLWebProfileResponders::PostImageResponder : public LLHTTPClient::Responde LOG_CLASS(LLWebProfileResponders::PostImageResponder); public: - /*virtual*/ void completedHeader(U32 status, const std::string& reason, const LLSD& content) + /*virtual*/ void completedRaw(const LLChannelDescriptors& channels, + const LLIOPipe::buffer_ptr_t& buffer) { // Viewer seems to fail to follow a 303 redirect on POST request // (URLRequest Error: 65, Send failed since rewinding of the data stream failed). // Handle it manually. - if (status == 303) + if (getStatus() == HTTP_SEE_OTHER) { LLSD headers = LLViewerMedia::getHeaders(); - headers["Cookie"] = LLWebProfile::getAuthCookie(); - const std::string& redir_url = content["location"]; - LL_DEBUGS("Snapshots") << "Got redirection URL: " << redir_url << llendl; - LLHTTPClient::get(redir_url, new LLWebProfileResponders::PostImageRedirectResponder(), headers); + headers[HTTP_OUT_HEADER_COOKIE] = LLWebProfile::getAuthCookie(); + const std::string& redir_url = getResponseHeader(HTTP_IN_HEADER_LOCATION); + if (redir_url.empty()) + { + LL_WARNS() << "Received empty redirection URL " << dumpResponse() << LL_ENDL; + LL_DEBUGS("Snapshots") << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; + LLWebProfile::reportImageUploadStatus(false); + } + else + { + LL_DEBUGS("Snapshots") << "Got redirection URL: " << redir_url << LL_ENDL; + LLHTTPClient::get(redir_url, new LLWebProfileResponders::PostImageRedirectResponder, headers); + } } else { - llwarns << "Unexpected POST status: " << status << " " << reason << llendl; - LL_DEBUGS("Snapshots") << "headers: [" << content << "]" << llendl; + LL_WARNS() << "Unexpected POST response " << dumpResponse() << LL_ENDL; + LL_DEBUGS("Snapshots") << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; LLWebProfile::reportImageUploadStatus(false); } } - - // Override just to suppress warnings. - /*virtual*/ void completedRaw(U32 status, const std::string& reason, - const LLChannelDescriptors& channels, - const LLIOPipe::buffer_ptr_t& buffer) - { - } }; /////////////////////////////////////////////////////////////////////////////// @@ -201,16 +201,16 @@ void LLWebProfile::uploadImage(LLPointer<LLImageFormatted> image, const std::str config_url += "?caption=" + LLURI::escape(caption); config_url += "&add_loc=" + std::string(add_location ? "1" : "0"); - LL_DEBUGS("Snapshots") << "Requesting " << config_url << llendl; + LL_DEBUGS("Snapshots") << "Requesting " << config_url << LL_ENDL; LLSD headers = LLViewerMedia::getHeaders(); - headers["Cookie"] = getAuthCookie(); + headers[HTTP_OUT_HEADER_COOKIE] = getAuthCookie(); LLHTTPClient::get(config_url, new LLWebProfileResponders::ConfigResponder(image), headers); } // static void LLWebProfile::setAuthCookie(const std::string& cookie) { - LL_DEBUGS("Snapshots") << "Setting auth cookie: " << cookie << llendl; + LL_DEBUGS("Snapshots") << "Setting auth cookie: " << cookie << LL_ENDL; sAuthCookie = cookie; } @@ -219,7 +219,7 @@ void LLWebProfile::post(LLPointer<LLImageFormatted> image, const LLSD& config, c { if (dynamic_cast<LLImagePNG*>(image.get()) == 0) { - llwarns << "Image to upload is not a PNG" << llendl; + LL_WARNS() << "Image to upload is not a PNG" << LL_ENDL; llassert(dynamic_cast<LLImagePNG*>(image.get()) != 0); return; } @@ -227,8 +227,8 @@ void LLWebProfile::post(LLPointer<LLImageFormatted> image, const LLSD& config, c const std::string boundary = "----------------------------0123abcdefab"; LLSD headers = LLViewerMedia::getHeaders(); - headers["Cookie"] = getAuthCookie(); - headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; + headers[HTTP_OUT_HEADER_COOKIE] = getAuthCookie(); + headers[HTTP_OUT_HEADER_CONTENT_TYPE] = "multipart/form-data; boundary=" + boundary; std::ostringstream body; |