HttpSession
The HttpSession is class responsible of receiving and sending data to a client :
- The received data are structured as a
HttpRequestin theRequestproperty. - The sending data are structured as a
HttpResponsein theResponseproperty.
Server
/// <summary>
/// Underlying SimpleW Server
/// </summary>
public readonly SimpleWServer Server;This property can be used to control Server from any Controller class.
JsonEngine
/// <summary>
/// Expose the Server.JsonEngine
/// </summary>
public IJsonEngine JsonEngine;See the interface. See the examples.
Request
/// <summary>
/// Last HttpRequest Parsed
/// </summary>
public HttpRequest Request;When HttpSession receive data from a client, it parses its content into a HttpRequest object and set the Request property. It supports http pipelining.
Response
/// <summary>
/// Current HttpResponse
/// </summary>
public HttpResponse Response;Before HttpSession call the Dispatcher to execute the underlying handler of the matched Route, it instanciates a new HttpResponse object and set the Response property.
NOTE
You should always used the Response to send data to a client.
Principal
/// <summary>
/// Principal
/// </summary>
public HttpPrincipal PrincipalThe current HttpPrincipal use for this session. See the examples.
Metadata
/// <summary>
/// Metadata attached to the currently matched handler.
/// Empty when no metadata is defined or no route matched yet.
/// </summary>
public HandlerMetadataCollection Metadata { get; internal set; }See the examples.
Bag
/// <summary>
/// Per-request transient storage shared across middlewares/handlers.
/// </summary>
public HttpBag Bag;See the class. See the examples.
ClientIPAddress
/// <summary>
/// Client IPAddress
/// </summary>
/// <returns></returns>
public IPAddress? ClientIpAddressSee the examples.
ClientCertificate
/// <summary>
/// ClientCertificate if exists in sslStream
/// </summary>
public X509Certificate2? ClientCertificateSendAsync
WARNING
The SendAsync methods bellow are the lowest level to send data to client. They are barely aliases of Socket.SendAsync() with a thread-safe guard. You should never need to use them but instead use the Response property to send data to a client.
/// <summary>
/// SendAsync native to socket (thread safe)
/// Lower level of sending
/// </summary>
/// <param name="buffer"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public async ValueTask SendAsync(ReadOnlyMemory<byte> buffer)/// <summary>
/// SendAsync to socket (thread safe)
/// Lower level of sending
/// </summary>
/// <param name="segments"></param>
/// <returns></returns>
public async ValueTask SendAsync(ArraySegment<byte>[] segments)/// <summary>
/// SendAsync to socket (thread safe)
/// Lower level of sending
/// </summary>
/// <param name="header"></param>
/// <param name="body"></param>
/// <returns></returns>
public async ValueTask SendAsync(ArraySegment<byte> header, ArraySegment<byte> body)/// <summary>
/// SendAsync to socket (thread safe)
/// Lower level of sending
/// </summary>
/// <param name="buffer"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public async ValueTask SendAsync(ArraySegment<byte> buffer)Socket
/// <summary>
/// Gets the underlying socket.
/// </summary>
public Socket Socket { get; }TransportStream
/// <summary>
/// Gets the underlying transport as a <see cref="Stream"/> (<see cref="NetworkStream"/> or <see cref="SslStream"/>).
/// Callers must not dispose this stream, as doing so would close the socket.
/// </summary>
public Stream TransportStream { get; }TryTakeTransportOwnership
/// <summary>
/// Stops HTTP parsing and transfers transport ownership.
/// </summary>
internal bool TryTakeTransportOwnership()