IWebInterfaceBrowserSchemeHandler.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Engine/Source/Runtime/WebBrowser/Public/IWebBrowserSchemeHandler.h
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. /**
  5. * This is the interface that needs to be implemented to handle a request made via a custom scheme.
  6. * It will be created by implementing an IWebBrowserSchemeHandlerFactory, given to the web browser singleton.
  7. */
  8. class WEBBROWSERUI_API IWebInterfaceBrowserSchemeHandler
  9. {
  10. public:
  11. /**
  12. * An interface for setting response headers emulating a http implementation.
  13. */
  14. class IHeaders
  15. {
  16. public:
  17. /**
  18. * Sets the mime type for the response.
  19. * @param MimeType The Mime Type.
  20. */
  21. virtual void SetMimeType(const TCHAR* MimeType) = 0;
  22. /**
  23. * Sets the status code for the response.
  24. * @param StatusCode The status code.
  25. */
  26. virtual void SetStatusCode(int32 StatusCode) = 0;
  27. /**
  28. * Sets the content length for the response.
  29. * @param ContentLength The size of the response content in bytes.
  30. */
  31. virtual void SetContentLength(int32 ContentLength) = 0;
  32. /**
  33. * Sets a redirect url for the response. Other calls will be ignored if this is used.
  34. * @param Url The url to redirect to.
  35. */
  36. virtual void SetRedirect(const TCHAR* Url) = 0;
  37. /**
  38. * Sets a header for the response.
  39. * @param Key The header key.
  40. * @param Value The header value.
  41. */
  42. virtual void SetHeader(const TCHAR* Key, const TCHAR* Value) = 0;
  43. };
  44. public:
  45. virtual ~IWebInterfaceBrowserSchemeHandler() {}
  46. /**
  47. * Process an incoming request.
  48. * @param Verb This is the verb used for the request (GET, PUT, POST, etc).
  49. * @param Url This is the full url for the request being made.
  50. * @param OnHeadersReady You must execute this delegate once the response headers are ready to be retrieved with GetResponseHeaders.
  51. * You may execute it during this call to state headers are available now.
  52. * @return You should return true if the request has been accepted and will be processed, otherwise false to cancel this request.
  53. */
  54. virtual bool ProcessRequest(const FString& Verb, const FString& Url, const FSimpleDelegate& OnHeadersReady) = 0;
  55. /**
  56. * Retrieves the headers for this request.
  57. * @param OutHeaders The interface to use to set headers.
  58. */
  59. virtual void GetResponseHeaders(IHeaders& OutHeaders) = 0;
  60. /**
  61. * Retrieves the headers for this request.
  62. * @param OutBytes You should copy up to BytesToRead of data to this ptr.
  63. * @param BytesToRead The maximum number of bytes that can be copied to OutBytes.
  64. * @param BytesRead You should set this to the number of bytes that were copied.
  65. * This can be set to zero, to indicate more data is not ready yet, and OnMoreDataReady must then be
  66. * executed when there is.
  67. * @param OnMoreDataReady You should execute this delegate when more data is available to read.
  68. * @return You should return true if more data needs to be read, otherwise false if this is the end of the response data.
  69. */
  70. virtual bool ReadResponse(uint8* OutBytes, int32 BytesToRead, int32& BytesRead, const FSimpleDelegate& OnMoreDataReady) = 0;
  71. /**
  72. * Called if the request should be canceled.
  73. */
  74. virtual void Cancel() = 0;
  75. };
  76. /**
  77. * This is the interface that needs to be implemented to instantiate a scheme request handler.
  78. */
  79. class WEBBROWSERUI_API IWebInterfaceBrowserSchemeHandlerFactory
  80. {
  81. public:
  82. virtual ~IWebInterfaceBrowserSchemeHandlerFactory() {}
  83. /**
  84. * Instantiates an appropriate handler for the given request details.
  85. * @param Verb This is the verb used for the request (GET, PUT, POST, etc).
  86. * @param Url This is the full url for the request being made.
  87. */
  88. virtual TUniquePtr<IWebInterfaceBrowserSchemeHandler> Create(FString Verb, FString Url) = 0;
  89. };