WrapHttpWebRequest.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. */
  8. using System;
  9. using System.IO;
  10. using System.Net;
  11. using UnityEngine;
  12. namespace Meta.WitAi
  13. {
  14. public class WrapHttpWebRequest : IRequest
  15. {
  16. HttpWebRequest _httpWebRequest;
  17. public WrapHttpWebRequest(HttpWebRequest httpWebRequest)
  18. {
  19. if (Application.isBatchMode)
  20. {
  21. httpWebRequest.KeepAlive = false;
  22. }
  23. _httpWebRequest = httpWebRequest;
  24. }
  25. public WebHeaderCollection Headers { get => _httpWebRequest.Headers; set => _httpWebRequest.Headers = value; }
  26. public string Method { get => _httpWebRequest.Method; set => _httpWebRequest.Method = value; }
  27. public string ContentType { get => _httpWebRequest.ContentType; set => _httpWebRequest.ContentType = value; }
  28. public long ContentLength { get => _httpWebRequest.ContentLength; set => _httpWebRequest.ContentLength = value; }
  29. public bool SendChunked { get => _httpWebRequest.SendChunked; set => _httpWebRequest.SendChunked = value; }
  30. public string UserAgent { get => _httpWebRequest.UserAgent; set => _httpWebRequest.UserAgent = value; }
  31. public int Timeout { get => _httpWebRequest.Timeout; set => _httpWebRequest.Timeout = value; }
  32. public void Abort()
  33. {
  34. _httpWebRequest.Abort();
  35. }
  36. public void Dispose()
  37. {
  38. _httpWebRequest.Abort();
  39. _httpWebRequest = null;
  40. }
  41. public IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
  42. {
  43. return _httpWebRequest.BeginGetRequestStream(callback, state);
  44. }
  45. public IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
  46. {
  47. return _httpWebRequest.BeginGetResponse(callback, state);
  48. }
  49. public Stream EndGetRequestStream(IAsyncResult asyncResult)
  50. {
  51. return _httpWebRequest.EndGetRequestStream(asyncResult);
  52. }
  53. public WebResponse EndGetResponse(IAsyncResult asyncResult)
  54. {
  55. return (_httpWebRequest).EndGetResponse(asyncResult);
  56. }
  57. }
  58. }