IExtension.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #if !BESTHTTP_DISABLE_WEBSOCKET && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using BestHTTP.PlatformSupport.Memory;
  3. using BestHTTP.WebSocket.Frames;
  4. namespace BestHTTP.WebSocket.Extensions
  5. {
  6. public interface IExtension
  7. {
  8. /// <summary>
  9. /// This is the first pass: here we can add headers to the request to initiate an extension negotiation.
  10. /// </summary>
  11. /// <param name="request"></param>
  12. void AddNegotiation(HTTPRequest request);
  13. /// <summary>
  14. /// If the websocket upgrade succeded it will call this function to be able to parse the server's negotiation
  15. /// response. Inside this function the IsEnabled should be set.
  16. /// </summary>
  17. bool ParseNegotiation(HTTPResponse resp);
  18. /// <summary>
  19. /// This function should return a new header flag based on the inFlag parameter. The extension should set only the
  20. /// Rsv1-3 bits in the header.
  21. /// </summary>
  22. byte GetFrameHeader(WebSocketFrame writer, byte inFlag);
  23. /// <summary>
  24. /// This function will be called to be able to transform the data that will be sent to the server.
  25. /// </summary>
  26. /// <param name="writer"></param>
  27. /// <returns></returns>
  28. BufferSegment Encode(WebSocketFrame writer);
  29. /// <summary>
  30. /// This function can be used the decode the server-sent data.
  31. /// </summary>
  32. BufferSegment Decode(byte header, BufferSegment data);
  33. }
  34. }
  35. #endif