llhttpsdhandler.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @file llhttpsdhandler.cpp
  3. * @brief Public-facing declarations for the HttpHandler class
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2012, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "llhttpsdhandler.h"
  28. #include "llcorebufferstream.h"
  29. #include "llcorehttpheaders.h"
  30. #include "llcorehttpresponse.h"
  31. #include "llcorehttputil.h"
  32. #include "llhttpconstants.h"
  33. #include "llsd.h"
  34. #include "llsdserialize.h"
  35. LLHttpSDHandler::LLHttpSDHandler()
  36. {
  37. }
  38. void LLHttpSDHandler::onCompleted(LLCore::HttpHandle handle,
  39. LLCore::HttpResponse* response)
  40. {
  41. LLCore::HttpStatus status = response->getStatus();
  42. if (!status)
  43. {
  44. this->onFailure(response, status);
  45. }
  46. else
  47. {
  48. LLSD resplsd;
  49. bool parsed = response->getBodySize() != 0 &&
  50. LLCoreHttpUtil::responseToLLSD(response, false, resplsd);
  51. if (!parsed)
  52. {
  53. // Only emit a warning if we failed to parse when
  54. // 'content-type' == 'application/llsd+xml'
  55. LLCore::HttpHeaders::ptr_t headers(response->getHeaders());
  56. const std::string* content_type = NULL;
  57. if (headers)
  58. {
  59. content_type = headers->find(HTTP_IN_HEADER_CONTENT_TYPE);
  60. }
  61. if (content_type && HTTP_CONTENT_LLSD_XML == *content_type)
  62. {
  63. std::string thebody = LLCoreHttpUtil::responseToString(response);
  64. llwarns << "Failed to deserialize: "
  65. << response->getRequestURL() << " - Status: "
  66. << response->getStatus().toString() << " - Body: "
  67. << thebody << llendl;
  68. }
  69. }
  70. this->onSuccess(response, resplsd);
  71. }
  72. }