/indra/llmessage/llhttpclient.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 162 lines · 81 code · 23 blank · 58 comment · 0 complexity · a9c2136273af730a28b4d52c07073c36 MD5 · raw file

  1. /**
  2. * @file llhttpclient.h
  3. * @brief Declaration of classes for making HTTP client requests.
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, 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. #ifndef LL_LLHTTPCLIENT_H
  27. #define LL_LLHTTPCLIENT_H
  28. /**
  29. * These classes represent the HTTP client framework.
  30. */
  31. #include <string>
  32. #include <boost/intrusive_ptr.hpp>
  33. #include <openssl/x509_vfy.h>
  34. #include "llurlrequest.h"
  35. #include "llassettype.h"
  36. #include "llcurl.h"
  37. #include "lliopipe.h"
  38. extern const F32 HTTP_REQUEST_EXPIRY_SECS;
  39. class LLUUID;
  40. class LLPumpIO;
  41. class LLSD;
  42. class LLHTTPClient
  43. {
  44. public:
  45. // class Responder moved to LLCurl
  46. // For convenience
  47. typedef LLCurl::Responder Responder;
  48. typedef LLCurl::ResponderPtr ResponderPtr;
  49. /** @name non-blocking API */
  50. //@{
  51. static void head(
  52. const std::string& url,
  53. ResponderPtr,
  54. const LLSD& headers = LLSD(),
  55. const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  56. static void getByteRange(const std::string& url, S32 offset, S32 bytes, ResponderPtr, const LLSD& headers=LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  57. static void get(const std::string& url, ResponderPtr, const LLSD& headers = LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  58. static void get(const std::string& url, const LLSD& query, ResponderPtr, const LLSD& headers = LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  59. static void put(
  60. const std::string& url,
  61. const LLSD& body,
  62. ResponderPtr,
  63. const LLSD& headers = LLSD(),
  64. const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  65. static void getHeaderOnly(const std::string& url, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  66. static void getHeaderOnly(const std::string& url, ResponderPtr, const LLSD& headers, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  67. static void post(
  68. const std::string& url,
  69. const LLSD& body,
  70. ResponderPtr,
  71. const LLSD& headers = LLSD(),
  72. const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  73. /** Takes ownership of data and deletes it when sent */
  74. static void postRaw(
  75. const std::string& url,
  76. const U8* data,
  77. S32 size,
  78. ResponderPtr responder,
  79. const LLSD& headers = LLSD(),
  80. const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  81. static void postFile(
  82. const std::string& url,
  83. const std::string& filename,
  84. ResponderPtr,
  85. const LLSD& headers = LLSD(),
  86. const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  87. static void postFile(
  88. const std::string& url,
  89. const LLUUID& uuid,
  90. LLAssetType::EType asset_type,
  91. ResponderPtr responder,
  92. const LLSD& headers = LLSD(),
  93. const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  94. static void del(
  95. const std::string& url,
  96. ResponderPtr responder,
  97. const LLSD& headers = LLSD(),
  98. const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  99. ///< sends a DELETE method, but we can't call it delete in c++
  100. /**
  101. * @brief Send a MOVE webdav method
  102. *
  103. * @param url The complete serialized (and escaped) url to get.
  104. * @param destination The complete serialized destination url.
  105. * @param responder The responder that will handle the result.
  106. * @param headers A map of key:value headers to pass to the request
  107. * @param timeout The number of seconds to give the server to respond.
  108. */
  109. static void move(
  110. const std::string& url,
  111. const std::string& destination,
  112. ResponderPtr responder,
  113. const LLSD& headers = LLSD(),
  114. const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
  115. //@}
  116. /**
  117. * @brief Blocking HTTP get that returns an LLSD map of status and body.
  118. *
  119. * @param url the complete serialized (and escaped) url to get
  120. * @return An LLSD of { 'status':status, 'body':payload }
  121. */
  122. static LLSD blockingGet(const std::string& url);
  123. /**
  124. * @brief Blocking HTTP POST that returns an LLSD map of status and body.
  125. *
  126. * @param url the complete serialized (and escaped) url to get
  127. * @param body the LLSD post body
  128. * @return An LLSD of { 'status':status (an int), 'body':payload (an LLSD) }
  129. */
  130. static LLSD blockingPost(const std::string& url, const LLSD& body);
  131. static void setPump(LLPumpIO& pump);
  132. ///< must be called before any of the above calls are made
  133. static bool hasPump();
  134. static void setCertVerifyCallback(LLURLRequest::SSLCertVerifyCallback callback);
  135. static LLURLRequest::SSLCertVerifyCallback getCertVerifyCallback() { return mCertVerifyCallback; }
  136. protected:
  137. static LLURLRequest::SSLCertVerifyCallback mCertVerifyCallback;
  138. };
  139. #endif // LL_LLHTTPCLIENT_H