HttpClientManager.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. using System.Collections.Specialized;
  2. using MediaBrowser.Common.Configuration;
  3. using MediaBrowser.Common.IO;
  4. using MediaBrowser.Common.Net;
  5. using MediaBrowser.Model.Logging;
  6. using MediaBrowser.Model.Net;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.Globalization;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Net;
  14. using System.Net.Cache;
  15. using System.Net.Http;
  16. using System.Reflection;
  17. using System.Text;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. namespace MediaBrowser.Common.Implementations.HttpClientManager
  21. {
  22. /// <summary>
  23. /// Class HttpClientManager
  24. /// </summary>
  25. public class HttpClientManager : IHttpClient
  26. {
  27. /// <summary>
  28. /// When one request to a host times out, we'll ban all other requests for this period of time, to prevent scans from stalling
  29. /// </summary>
  30. private const int TimeoutSeconds = 30;
  31. /// <summary>
  32. /// The _logger
  33. /// </summary>
  34. private readonly ILogger _logger;
  35. /// <summary>
  36. /// The _app paths
  37. /// </summary>
  38. private readonly IApplicationPaths _appPaths;
  39. private readonly IFileSystem _fileSystem;
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="HttpClientManager" /> class.
  42. /// </summary>
  43. /// <param name="appPaths">The app paths.</param>
  44. /// <param name="logger">The logger.</param>
  45. /// <param name="fileSystem">The file system.</param>
  46. /// <exception cref="System.ArgumentNullException">appPaths
  47. /// or
  48. /// logger</exception>
  49. public HttpClientManager(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem)
  50. {
  51. if (appPaths == null)
  52. {
  53. throw new ArgumentNullException("appPaths");
  54. }
  55. if (logger == null)
  56. {
  57. throw new ArgumentNullException("logger");
  58. }
  59. _logger = logger;
  60. _fileSystem = fileSystem;
  61. _appPaths = appPaths;
  62. // http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
  63. ServicePointManager.Expect100Continue = false;
  64. }
  65. /// <summary>
  66. /// Holds a dictionary of http clients by host. Use GetHttpClient(host) to retrieve or create a client for web requests.
  67. /// DON'T dispose it after use.
  68. /// </summary>
  69. /// <value>The HTTP clients.</value>
  70. private readonly ConcurrentDictionary<string, HttpClientInfo> _httpClients = new ConcurrentDictionary<string, HttpClientInfo>();
  71. /// <summary>
  72. /// Gets
  73. /// </summary>
  74. /// <param name="host">The host.</param>
  75. /// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
  76. /// <returns>HttpClient.</returns>
  77. /// <exception cref="System.ArgumentNullException">host</exception>
  78. private HttpClientInfo GetHttpClient(string host, bool enableHttpCompression)
  79. {
  80. if (string.IsNullOrEmpty(host))
  81. {
  82. throw new ArgumentNullException("host");
  83. }
  84. HttpClientInfo client;
  85. var key = host + enableHttpCompression;
  86. if (!_httpClients.TryGetValue(key, out client))
  87. {
  88. client = new HttpClientInfo();
  89. _httpClients.TryAdd(key, client);
  90. }
  91. return client;
  92. }
  93. private PropertyInfo _httpBehaviorPropertyInfo;
  94. private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
  95. {
  96. var request = (HttpWebRequest)WebRequest.Create(options.Url);
  97. AddRequestHeaders(request, options);
  98. request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
  99. request.CachePolicy = options.CachePolicy == Net.HttpRequestCachePolicy.None ?
  100. new RequestCachePolicy(RequestCacheLevel.BypassCache) :
  101. new RequestCachePolicy(RequestCacheLevel.Revalidate);
  102. request.ConnectionGroupName = GetHostFromUrl(options.Url);
  103. request.KeepAlive = true;
  104. request.Method = method;
  105. request.Pipelined = true;
  106. request.Timeout = 20000;
  107. #if !__MonoCS__
  108. // This is a hack to prevent KeepAlive from getting disabled internally by the HttpWebRequest
  109. // May need to remove this for mono
  110. var sp = request.ServicePoint;
  111. if (_httpBehaviorPropertyInfo == null)
  112. {
  113. _httpBehaviorPropertyInfo = sp.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
  114. }
  115. _httpBehaviorPropertyInfo.SetValue(sp, (byte)0, null);
  116. #endif
  117. return request;
  118. }
  119. private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options)
  120. {
  121. foreach (var header in options.RequestHeaders.ToList())
  122. {
  123. if (string.Equals(header.Key, "Accept", StringComparison.OrdinalIgnoreCase))
  124. {
  125. request.Accept = header.Value;
  126. }
  127. else if (string.Equals(header.Key, "User-Agent", StringComparison.OrdinalIgnoreCase))
  128. {
  129. request.UserAgent = header.Value;
  130. }
  131. else
  132. {
  133. request.Headers.Set(header.Key, header.Value);
  134. }
  135. }
  136. }
  137. /// <summary>
  138. /// Gets the response internal.
  139. /// </summary>
  140. /// <param name="options">The options.</param>
  141. /// <returns>Task{HttpResponseInfo}.</returns>
  142. /// <exception cref="HttpException">
  143. /// </exception>
  144. public Task<HttpResponseInfo> GetResponse(HttpRequestOptions options)
  145. {
  146. return SendAsync(options, "GET");
  147. }
  148. /// <summary>
  149. /// Performs a GET request and returns the resulting stream
  150. /// </summary>
  151. /// <param name="options">The options.</param>
  152. /// <returns>Task{Stream}.</returns>
  153. /// <exception cref="HttpException"></exception>
  154. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  155. public async Task<Stream> Get(HttpRequestOptions options)
  156. {
  157. var response = await GetResponse(options).ConfigureAwait(false);
  158. return response.Content;
  159. }
  160. /// <summary>
  161. /// Performs a GET request and returns the resulting stream
  162. /// </summary>
  163. /// <param name="url">The URL.</param>
  164. /// <param name="resourcePool">The resource pool.</param>
  165. /// <param name="cancellationToken">The cancellation token.</param>
  166. /// <returns>Task{Stream}.</returns>
  167. public Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
  168. {
  169. return Get(new HttpRequestOptions
  170. {
  171. Url = url,
  172. ResourcePool = resourcePool,
  173. CancellationToken = cancellationToken,
  174. });
  175. }
  176. /// <summary>
  177. /// Gets the specified URL.
  178. /// </summary>
  179. /// <param name="url">The URL.</param>
  180. /// <param name="cancellationToken">The cancellation token.</param>
  181. /// <returns>Task{Stream}.</returns>
  182. public Task<Stream> Get(string url, CancellationToken cancellationToken)
  183. {
  184. return Get(url, null, cancellationToken);
  185. }
  186. /// <summary>
  187. /// send as an asynchronous operation.
  188. /// </summary>
  189. /// <param name="options">The options.</param>
  190. /// <param name="httpMethod">The HTTP method.</param>
  191. /// <returns>Task{HttpResponseInfo}.</returns>
  192. /// <exception cref="HttpException">
  193. /// </exception>
  194. private async Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, string httpMethod)
  195. {
  196. ValidateParams(options);
  197. options.CancellationToken.ThrowIfCancellationRequested();
  198. var client = GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression);
  199. if ((DateTime.UtcNow - client.LastTimeout).TotalSeconds < TimeoutSeconds)
  200. {
  201. throw new HttpException(string.Format("Cancelling connection to {0} due to a previous timeout.", options.Url)) { IsTimedOut = true };
  202. }
  203. var httpWebRequest = GetRequest(options, httpMethod, options.EnableHttpCompression);
  204. if (!string.IsNullOrEmpty(options.RequestContent) || string.Equals(httpMethod, "post", StringComparison.OrdinalIgnoreCase))
  205. {
  206. var content = options.RequestContent ?? string.Empty;
  207. var bytes = Encoding.UTF8.GetBytes(content);
  208. httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded";
  209. httpWebRequest.ContentLength = bytes.Length;
  210. httpWebRequest.GetRequestStream().Write(bytes, 0, bytes.Length);
  211. }
  212. if (options.ResourcePool != null)
  213. {
  214. await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
  215. }
  216. if ((DateTime.UtcNow - client.LastTimeout).TotalSeconds < TimeoutSeconds)
  217. {
  218. if (options.ResourcePool != null)
  219. {
  220. options.ResourcePool.Release();
  221. }
  222. throw new HttpException(string.Format("Connection to {0} timed out", options.Url)) { IsTimedOut = true };
  223. }
  224. if (options.LogRequest)
  225. {
  226. _logger.Info("HttpClientManager {0}: {1}", httpMethod.ToUpper(), options.Url);
  227. }
  228. try
  229. {
  230. options.CancellationToken.ThrowIfCancellationRequested();
  231. if (!options.BufferContent)
  232. {
  233. var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false);
  234. var httpResponse = (HttpWebResponse)response;
  235. EnsureSuccessStatusCode(httpResponse);
  236. options.CancellationToken.ThrowIfCancellationRequested();
  237. return GetResponseInfo(httpResponse, httpResponse.GetResponseStream(), GetContentLength(httpResponse));
  238. }
  239. using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false))
  240. {
  241. var httpResponse = (HttpWebResponse)response;
  242. EnsureSuccessStatusCode(httpResponse);
  243. options.CancellationToken.ThrowIfCancellationRequested();
  244. using (var stream = httpResponse.GetResponseStream())
  245. {
  246. var memoryStream = new MemoryStream();
  247. await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
  248. memoryStream.Position = 0;
  249. return GetResponseInfo(httpResponse, memoryStream, memoryStream.Length);
  250. }
  251. }
  252. }
  253. catch (OperationCanceledException ex)
  254. {
  255. var exception = GetCancellationException(options.Url, options.CancellationToken, ex);
  256. var httpException = exception as HttpException;
  257. if (httpException != null && httpException.IsTimedOut)
  258. {
  259. client.LastTimeout = DateTime.UtcNow;
  260. }
  261. throw exception;
  262. }
  263. catch (HttpRequestException ex)
  264. {
  265. _logger.ErrorException("Error getting response from " + options.Url, ex);
  266. throw new HttpException(ex.Message, ex);
  267. }
  268. catch (WebException ex)
  269. {
  270. _logger.ErrorException("Error getting response from " + options.Url, ex);
  271. throw new HttpException(ex.Message, ex);
  272. }
  273. catch (Exception ex)
  274. {
  275. _logger.ErrorException("Error getting response from " + options.Url, ex);
  276. throw;
  277. }
  278. finally
  279. {
  280. if (options.ResourcePool != null)
  281. {
  282. options.ResourcePool.Release();
  283. }
  284. }
  285. }
  286. private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, Stream content, long? contentLength)
  287. {
  288. return new HttpResponseInfo
  289. {
  290. Content = content,
  291. StatusCode = httpResponse.StatusCode,
  292. ContentType = httpResponse.ContentType,
  293. Headers = new NameValueCollection(httpResponse.Headers),
  294. ContentLength = contentLength
  295. };
  296. }
  297. private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, string tempFile, long? contentLength)
  298. {
  299. return new HttpResponseInfo
  300. {
  301. TempFilePath = tempFile,
  302. StatusCode = httpResponse.StatusCode,
  303. ContentType = httpResponse.ContentType,
  304. Headers = httpResponse.Headers,
  305. ContentLength = contentLength
  306. };
  307. }
  308. public Task<HttpResponseInfo> Post(HttpRequestOptions options)
  309. {
  310. return SendAsync(options, "POST");
  311. }
  312. /// <summary>
  313. /// Performs a POST request
  314. /// </summary>
  315. /// <param name="options">The options.</param>
  316. /// <param name="postData">Params to add to the POST data.</param>
  317. /// <returns>stream on success, null on failure</returns>
  318. /// <exception cref="HttpException">
  319. /// </exception>
  320. /// <exception cref="System.ArgumentNullException">postData</exception>
  321. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  322. public async Task<Stream> Post(HttpRequestOptions options, Dictionary<string, string> postData)
  323. {
  324. var strings = postData.Keys.Select(key => string.Format("{0}={1}", key, postData[key]));
  325. var postContent = string.Join("&", strings.ToArray());
  326. options.RequestContent = postContent;
  327. options.RequestContentType = "application/x-www-form-urlencoded";
  328. var response = await Post(options).ConfigureAwait(false);
  329. return response.Content;
  330. }
  331. /// <summary>
  332. /// Performs a POST request
  333. /// </summary>
  334. /// <param name="url">The URL.</param>
  335. /// <param name="postData">Params to add to the POST data.</param>
  336. /// <param name="resourcePool">The resource pool.</param>
  337. /// <param name="cancellationToken">The cancellation token.</param>
  338. /// <returns>stream on success, null on failure</returns>
  339. public Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
  340. {
  341. return Post(new HttpRequestOptions
  342. {
  343. Url = url,
  344. ResourcePool = resourcePool,
  345. CancellationToken = cancellationToken
  346. }, postData);
  347. }
  348. /// <summary>
  349. /// Downloads the contents of a given url into a temporary location
  350. /// </summary>
  351. /// <param name="options">The options.</param>
  352. /// <returns>Task{System.String}.</returns>
  353. /// <exception cref="System.ArgumentNullException">progress</exception>
  354. /// <exception cref="HttpException"></exception>
  355. /// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
  356. public async Task<string> GetTempFile(HttpRequestOptions options)
  357. {
  358. var response = await GetTempFileResponse(options).ConfigureAwait(false);
  359. return response.TempFilePath;
  360. }
  361. public async Task<HttpResponseInfo> GetTempFileResponse(HttpRequestOptions options)
  362. {
  363. ValidateParams(options);
  364. Directory.CreateDirectory(_appPaths.TempDirectory);
  365. var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp");
  366. if (options.Progress == null)
  367. {
  368. throw new ArgumentNullException("progress");
  369. }
  370. options.CancellationToken.ThrowIfCancellationRequested();
  371. var httpWebRequest = GetRequest(options, "GET", options.EnableHttpCompression);
  372. if (options.ResourcePool != null)
  373. {
  374. await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
  375. }
  376. options.Progress.Report(0);
  377. if (options.LogRequest)
  378. {
  379. _logger.Info("HttpClientManager.GetTempFileResponse url: {0}", options.Url);
  380. }
  381. try
  382. {
  383. options.CancellationToken.ThrowIfCancellationRequested();
  384. using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false))
  385. {
  386. var httpResponse = (HttpWebResponse)response;
  387. EnsureSuccessStatusCode(httpResponse);
  388. options.CancellationToken.ThrowIfCancellationRequested();
  389. var contentLength = GetContentLength(httpResponse);
  390. if (!contentLength.HasValue)
  391. {
  392. // We're not able to track progress
  393. using (var stream = httpResponse.GetResponseStream())
  394. {
  395. using (var fs = _fileSystem.GetFileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, true))
  396. {
  397. await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
  398. }
  399. }
  400. }
  401. else
  402. {
  403. using (var stream = ProgressStream.CreateReadProgressStream(httpResponse.GetResponseStream(), options.Progress.Report, contentLength.Value))
  404. {
  405. using (var fs = _fileSystem.GetFileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, true))
  406. {
  407. await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
  408. }
  409. }
  410. }
  411. options.Progress.Report(100);
  412. return GetResponseInfo(httpResponse, tempFile, contentLength);
  413. }
  414. }
  415. catch (OperationCanceledException ex)
  416. {
  417. throw GetTempFileException(ex, options, tempFile);
  418. }
  419. catch (HttpRequestException ex)
  420. {
  421. throw GetTempFileException(ex, options, tempFile);
  422. }
  423. catch (WebException ex)
  424. {
  425. throw GetTempFileException(ex, options, tempFile);
  426. }
  427. catch (Exception ex)
  428. {
  429. throw GetTempFileException(ex, options, tempFile);
  430. }
  431. finally
  432. {
  433. if (options.ResourcePool != null)
  434. {
  435. options.ResourcePool.Release();
  436. }
  437. }
  438. }
  439. private long? GetContentLength(HttpWebResponse response)
  440. {
  441. var length = response.ContentLength;
  442. if (length == 0)
  443. {
  444. return null;
  445. }
  446. return length;
  447. }
  448. protected static readonly CultureInfo UsCulture = new CultureInfo("en-US");
  449. /// <summary>
  450. /// Handles the temp file exception.
  451. /// </summary>
  452. /// <param name="ex">The ex.</param>
  453. /// <param name="options">The options.</param>
  454. /// <param name="tempFile">The temp file.</param>
  455. /// <returns>Task.</returns>
  456. /// <exception cref="HttpException"></exception>
  457. private Exception GetTempFileException(Exception ex, HttpRequestOptions options, string tempFile)
  458. {
  459. var operationCanceledException = ex as OperationCanceledException;
  460. if (operationCanceledException != null)
  461. {
  462. // Cleanup
  463. DeleteTempFile(tempFile);
  464. return GetCancellationException(options.Url, options.CancellationToken, operationCanceledException);
  465. }
  466. _logger.ErrorException("Error getting response from " + options.Url, ex);
  467. // Cleanup
  468. DeleteTempFile(tempFile);
  469. var httpRequestException = ex as HttpRequestException;
  470. if (httpRequestException != null)
  471. {
  472. return new HttpException(ex.Message, ex);
  473. }
  474. var webException = ex as WebException;
  475. if (webException != null)
  476. {
  477. return new HttpException(ex.Message, ex);
  478. }
  479. return ex;
  480. }
  481. private void DeleteTempFile(string file)
  482. {
  483. try
  484. {
  485. File.Delete(file);
  486. }
  487. catch (IOException)
  488. {
  489. // Might not have been created at all. No need to worry.
  490. }
  491. }
  492. private void ValidateParams(HttpRequestOptions options)
  493. {
  494. if (string.IsNullOrEmpty(options.Url))
  495. {
  496. throw new ArgumentNullException("options");
  497. }
  498. }
  499. /// <summary>
  500. /// Gets the host from URL.
  501. /// </summary>
  502. /// <param name="url">The URL.</param>
  503. /// <returns>System.String.</returns>
  504. private string GetHostFromUrl(string url)
  505. {
  506. var start = url.IndexOf("://", StringComparison.OrdinalIgnoreCase) + 3;
  507. var len = url.IndexOf('/', start) - start;
  508. return url.Substring(start, len);
  509. }
  510. /// <summary>
  511. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  512. /// </summary>
  513. public void Dispose()
  514. {
  515. Dispose(true);
  516. GC.SuppressFinalize(this);
  517. }
  518. /// <summary>
  519. /// Releases unmanaged and - optionally - managed resources.
  520. /// </summary>
  521. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  522. protected virtual void Dispose(bool dispose)
  523. {
  524. if (dispose)
  525. {
  526. _httpClients.Clear();
  527. }
  528. }
  529. /// <summary>
  530. /// Throws the cancellation exception.
  531. /// </summary>
  532. /// <param name="url">The URL.</param>
  533. /// <param name="cancellationToken">The cancellation token.</param>
  534. /// <param name="exception">The exception.</param>
  535. /// <returns>Exception.</returns>
  536. private Exception GetCancellationException(string url, CancellationToken cancellationToken, OperationCanceledException exception)
  537. {
  538. // If the HttpClient's timeout is reached, it will cancel the Task internally
  539. if (!cancellationToken.IsCancellationRequested)
  540. {
  541. var msg = string.Format("Connection to {0} timed out", url);
  542. _logger.Error(msg);
  543. // Throw an HttpException so that the caller doesn't think it was cancelled by user code
  544. return new HttpException(msg, exception) { IsTimedOut = true };
  545. }
  546. return exception;
  547. }
  548. private void EnsureSuccessStatusCode(HttpWebResponse response)
  549. {
  550. var statusCode = response.StatusCode;
  551. var isSuccessful = statusCode >= HttpStatusCode.OK && statusCode <= (HttpStatusCode)299;
  552. if (!isSuccessful)
  553. {
  554. throw new HttpException(response.StatusDescription) { StatusCode = response.StatusCode };
  555. }
  556. }
  557. /// <summary>
  558. /// Posts the specified URL.
  559. /// </summary>
  560. /// <param name="url">The URL.</param>
  561. /// <param name="postData">The post data.</param>
  562. /// <param name="cancellationToken">The cancellation token.</param>
  563. /// <returns>Task{Stream}.</returns>
  564. public Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken)
  565. {
  566. return Post(url, postData, null, cancellationToken);
  567. }
  568. }
  569. }