HttpProfile.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /*
  3. * Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing,
  12. * software distributed under the License is distributed on an
  13. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. * KIND, either express or implied. See the License for the
  15. * specific language governing permissions and limitations
  16. * under the License.
  17. */
  18. namespace TencentCloud\Common\Profile;
  19. /**
  20. * http相关参数类
  21. * Class HttpProfile
  22. * @package TencentCloud\Common\Profile
  23. */
  24. class HttpProfile
  25. {
  26. /**
  27. * @var string https访问
  28. */
  29. public static $REQ_HTTPS = "https://";
  30. /**
  31. * @var string http访问
  32. */
  33. public static $REQ_HTTP = "http://";
  34. /**
  35. * @var string post请求
  36. */
  37. public static $REQ_POST = "POST";
  38. /**
  39. * @var string get请求
  40. */
  41. public static $REQ_GET = "GET";
  42. /**
  43. * @var int 时间一分钟
  44. */
  45. public static $TM_MINUTE = 60;
  46. /**
  47. * @var string http请求方法
  48. */
  49. private $reqMethod;
  50. /**
  51. * @var string 请求接入点域名
  52. */
  53. private $endpoint;
  54. /**
  55. * @var integer 请求超时时长,单位为秒
  56. */
  57. private $reqTimeout;
  58. /**
  59. * @var string 请求协议
  60. */
  61. private $protocol;
  62. /**
  63. * @var string|array 请求代理
  64. */
  65. private $proxy;
  66. /**
  67. * @var string
  68. */
  69. private $rootDomain;
  70. /**
  71. * @var boolean
  72. */
  73. private $keepAlive;
  74. /**
  75. * HttpProfile constructor.
  76. * @param string $protocol 请求协议
  77. * @param string $endpoint 请求接入点域名(xx.[region.]tencentcloudapi.com)
  78. * @param string $reqMethod http请求方法,目前支持POST GET
  79. * @param integer $reqTimeout 请求超时时间,单位:s
  80. */
  81. public function __construct($protocol = null, $endpoint = null, $reqMethod = null, $reqTimeout = null)
  82. {
  83. $this->reqMethod = $reqMethod ? $reqMethod : HttpProfile::$REQ_POST;
  84. $this->endpoint = $endpoint;
  85. $this->reqTimeout = $reqTimeout ? $reqTimeout : HttpProfile::$TM_MINUTE;
  86. $this->protocol = $protocol ? $protocol : HttpProfile::$REQ_HTTPS;
  87. $this->rootDomain = "tencentcloudapi.com";
  88. $this->keepAlive = false;
  89. }
  90. /**
  91. * 设置http请求方法
  92. * @param string $reqMethod http请求方法,目前支持POST GET
  93. */
  94. public function setReqMethod($reqMethod)
  95. {
  96. $this->reqMethod = $reqMethod;
  97. }
  98. /**
  99. * 设置请求协议
  100. * @param string $protocol 请求协议(https:// http://)
  101. */
  102. public function setProtocol($protocol) {
  103. $this->protocol = $protocol;
  104. }
  105. /**
  106. * 设置请求接入点域名
  107. * @param string $endpoint 请求接入点域名(xx.[region.]tencentcloudapi.com)
  108. */
  109. public function setEndpoint($endpoint)
  110. {
  111. $this->endpoint = $endpoint;
  112. }
  113. /**
  114. * 设置请求超时时间
  115. * @param integer $reqTimeout 请求超时时间,单位:s
  116. */
  117. public function setReqTimeout($reqTimeout)
  118. {
  119. $this->reqTimeout = $reqTimeout;
  120. }
  121. /**
  122. * 设置请求代理
  123. * @param string|array $proxy 请求代理配置
  124. */
  125. public function setProxy($proxy)
  126. {
  127. $this->proxy = $proxy;
  128. }
  129. /**
  130. * 获取请求方法
  131. * @return null|string 请求方法
  132. */
  133. public function getReqMethod()
  134. {
  135. return $this->reqMethod;
  136. }
  137. /**
  138. * 获取请求协议
  139. * @return null|string 请求协议
  140. */
  141. public function getProtocol()
  142. {
  143. return $this->protocol;
  144. }
  145. /**
  146. * 获取请求超时时间
  147. * @return int 请求超时时间
  148. */
  149. public function getReqTimeout()
  150. {
  151. return $this->reqTimeout;
  152. }
  153. /**
  154. * 获取请求接入点域名
  155. * @return null|string 接入点域名
  156. */
  157. public function getEndpoint()
  158. {
  159. return $this->endpoint;
  160. }
  161. /**
  162. * 获取请求代理
  163. * @return null|string|array
  164. */
  165. public function getProxy()
  166. {
  167. return $this->proxy;
  168. }
  169. public function setRootDomain($domain)
  170. {
  171. $this->rootDomain = $domain;
  172. }
  173. public function getRootDomain()
  174. {
  175. return $this->rootDomain;
  176. }
  177. /**
  178. * @param boolean $flag
  179. */
  180. public function setKeepAlive($flag) {
  181. $this->keepAlive = $flag;
  182. }
  183. public function getKeepAlive() {
  184. return $this->keepAlive;
  185. }
  186. }