Livt packages

Livt.Web

Version 1.0.0

Bounded HTTP routing, request parsing, response encoding, and Ethernet application composition for Livt.

Published files (63)

src/http/HttpServer.lvt

namespace Livt.Web.Http

using Livt.Net

/**
 * Default HTTP server assembly over one shared capture/parser graph.
 * Owns router, application encoder and network adapter; borrows source and routes.
 * Advanced consumers may compose these three layers separately.
 */
component HttpServer<S: IPacketData, T: IHttpRoute, CAPACITY: int = 1514> : IPacketData
{
	// Owned composition nodes; shared references never create another instance.
	router: HttpRouter<T>
	application: HttpApplication<TcpConnectionRecognizer<S>, T>

	endpoint: HttpNetworkEndpoint<S, HttpApplication<TcpConnectionRecognizer<S>, T>, CAPACITY>

	/**
	 * All parsers and routes must share this exact source/request graph and reset domain.
	 * Does not acquire/release receive storage. Retain it until TryRelease succeeds.
	 */
	new(source: S, ethernet: EthernetFrameParser<S>, ipv4: Ipv4PacketParser<EthernetFrameParser<S>>,
		connection: TcpConnectionRecognizer<S>, request: HttpRequestParser<TcpConnectionRecognizer<S>>, routes: T,
		localMac: byte[6], localIp: byte[4], localPort: byte[2])
	{
		this.router = new HttpRouter<T>(routes)
		this.application = new HttpApplication<TcpConnectionRecognizer<S>, T>(request, router)
		this.endpoint = new HttpNetworkEndpoint<S, HttpApplication<TcpConnectionRecognizer<S>, T>, CAPACITY>(source, ethernet, ipv4, connection, application, localMac, localIp, localPort)
	}

	/**
	 * Handles one stable published capture; returns the existing phase while active.
	 * Requires an acquired source and no outstanding readers of the previous frame.
	 */
	public fn HandleFrame() HttpTransportState
	{
		return this.endpoint.HandleFrame()
	}

	/**
	 * Resumes Pending work without repeating accepted handler actions.
	 */
	public fn Poll() HttpTransportState
	{
		return this.endpoint.Poll()
	}

	/**
	 * Returns the current lifecycle phase without progressing work.
	 */
	public fn GetState() HttpTransportState
	{
		return this.endpoint.GetState()
	}

	/**
	 * Returns the selected protocol kind, independent of application route identity.
	 */
	public fn GetResponseKind() HttpNetworkResponse
	{
		return this.endpoint.GetResponseKind()
	}

	/**
	 * Records successful local emission and retains readable bytes.
	 * Call only after first emission; success is not peer acknowledgement.
	 */
	public fn MarkEmitted() bool
	{
		return this.endpoint.MarkEmitted()
	}

	/**
	 * Closes a Retained response after all downstream readers stop.
	 * Returns false outside Retained or when completion fails.
	 */
	public fn Complete() bool
	{
		return this.endpoint.Complete()
	}

	/**
	 * Cancels active work and resets the narrow TCP session.
	 * Requires stopped downstream readers; does not release caller-owned RX.
	 */
	public fn Abort()
	{
		this.endpoint.Abort()
	}

	/**
	 * Closes inactive views and returns Success before RX reuse.
	 * Pending, Prepared and Retained return Busy and retain their borrows.
	 */
	public fn TryRelease() PacketDataResult
	{
		return this.endpoint.TryRelease()
	}

	/**
	 * Reports current Prepared/Retained publication availability, not a reservation.
	 */
	override fn IsReady() bool
	{
		return this.endpoint.IsReady()
	}

	/**
	 * Returns the complete Ethernet frame byte extent, or zero without publication.
	 */
	override fn GetAvailableLength() int
	{
		return this.endpoint.GetAvailableLength()
	}

	/**
	 * Reads a checked zero-based frame byte while published.
	 * Check PacketDataResult before using value; retain RX and body providers.
	 */
	override fn TryRead(index: int, value: out byte) PacketDataResult
	{
		return this.endpoint.TryRead(index, value)
	}

}