llcorehttpoptions.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * @file llcorehttpoptions.h
  3. * @brief Public-facing declarations for the HTTPOptions 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. #ifndef _LLCORE_HTTP_OPTIONS_H_
  27. #define _LLCORE_HTTP_OPTIONS_H_
  28. #include "llcorehttpcommon.h"
  29. // Convenient shortcut
  30. #define DEFAULT_HTTP_OPTIONS std::make_shared<LLCore::HttpOptions>()
  31. namespace LLCore
  32. {
  33. // Really a struct in spirit, it provides options that modify HTTP requests.
  34. //
  35. // Sharing instances across requests. It is intended that these be shared
  36. // across requests: caller can create one of these, set it up as needed and
  37. // then reference it repeatedly in HTTP operations. But see the Threading note
  38. // about references.
  39. //
  40. // Threading: While this class does nothing to ensure thread safety, it *is*
  41. // intended to be shared between the application thread and the worker thread.
  42. // This means that once an instance is delivered to the library in request
  43. // operations, the option data must not be written until all such requests
  44. // complete and relinquish their references.
  45. //
  46. // Allocation: Refcounted, heap only. Caller of the constructor is given a
  47. // refcount.
  48. class HttpOptions
  49. {
  50. public:
  51. typedef std::shared_ptr<HttpOptions> ptr_t;
  52. HttpOptions();
  53. // Non-copyable
  54. HttpOptions(const HttpOptions&) = delete;
  55. HttpOptions& operator=(const HttpOptions&) = delete;
  56. public:
  57. // Default: false
  58. LL_INLINE void setWantHeaders(bool wanted) { mWantHeaders = wanted; }
  59. LL_INLINE bool getWantHeaders() const { return mWantHeaders; }
  60. // Default: 0
  61. LL_INLINE void setTrace(S32 level) { mTracing = level; }
  62. LL_INLINE S32 getTrace() const { return mTracing; }
  63. // Default: 30
  64. LL_INLINE void setTimeout(U32 timeout) { mTimeout = timeout; }
  65. LL_INLINE U32 getTimeout() const { return mTimeout; }
  66. // Default: 0
  67. LL_INLINE void setTransferTimeout(U32 t) { mTransferTimeout = t; }
  68. LL_INLINE U32 getTransferTimeout() const { return mTransferTimeout; }
  69. // Sets the number of retries on an LLCore::HTTPRequest before the request
  70. // fails. Default: 8
  71. LL_INLINE void setRetries(U32 retries) { mRetries = retries; }
  72. LL_INLINE U32 getRetries() const { return mRetries; }
  73. // Default: true
  74. LL_INLINE void setUseRetryAfter(bool use_retry) { mUseRetryAfter = use_retry; }
  75. LL_INLINE bool getUseRetryAfter() const { return mUseRetryAfter; }
  76. // Instructs the LLCore::HTTPRequest to follow redirects. Default: false
  77. LL_INLINE void setFollowRedirects(bool follow) { mFollowRedirects = follow; }
  78. LL_INLINE bool getFollowRedirects() const { return mFollowRedirects; }
  79. // Instructs the LLCore::HTTPRequest to verify that the exchanged security
  80. // certificate is authentic. Default: false
  81. LL_INLINE void setSSLVerifyPeer(bool verify) { mVerifyPeer = verify; }
  82. LL_INLINE bool getSSLVerifyPeer() const { return mVerifyPeer; }
  83. // Instructs the LLCore::HTTPRequest to verify that the name in the
  84. // security certificate matches the name of the host contacted.
  85. // Default: false
  86. LL_INLINE void setSSLVerifyHost(bool verify) { mVerifyHost = verify; }
  87. LL_INLINE bool getSSLVerifyHost() const { return mVerifyHost; }
  88. // Sets the time for DNS name caching in seconds. Setting this value to 0
  89. // will disable name caching. Setting this value to -1 causes the name
  90. // cache to never time out. Default: -1
  91. void setDNSCacheTimeout(S32 timeout) { mDNSCacheTimeout = timeout; }
  92. LL_INLINE S32 getDNSCacheTimeout() const { return mDNSCacheTimeout; }
  93. // Retrieve only the headers and status from the request. Setting this to
  94. // true implies setWantHeaders(true) as well. Default: false
  95. LL_INLINE void setHeadersOnly(bool nobody)
  96. {
  97. mNoBody = nobody;
  98. if (mNoBody)
  99. {
  100. mWantHeaders = true;
  101. }
  102. }
  103. LL_INLINE bool getHeadersOnly() const { return mNoBody; }
  104. protected:
  105. S32 mTracing;
  106. S32 mDNSCacheTimeout;
  107. U32 mTimeout;
  108. U32 mTransferTimeout;
  109. U32 mRetries;
  110. bool mWantHeaders;
  111. bool mUseRetryAfter;
  112. bool mFollowRedirects;
  113. bool mVerifyPeer;
  114. bool mVerifyHost;
  115. bool mNoBody;
  116. };
  117. } // End namespace LLCore
  118. #endif // _LLCORE_HTTP_OPTIONS_H_