Defines the contract for a driver-specific context for a single HTTP request.

This interface abstracts away the underlying server implementation (e.g., Socket, Undertow) from the main HttpHandler. It is responsible for all I/O operations and for translating native request/response objects into the framework's common objects.

It provides two mutually exclusive ways to send a response: 1. writeResponse(response): For simple, buffered responses that are sent in one go. 2. beginWrite() followed by write* methods: For manual/streaming responses.

Variables

@:isVarread onlyinput:Input

Input stream used to read the request body.

@:isVarread onlyoutput:Output

Output stream used to write the response to the client.

Methods

beginWrite():Void

Begins a manual/streaming response. This sends the HTTP status line and headers, preparing the stream for the body content. This must be called before any write* methods are used for streaming.

close():Void

Closes the connection and releases all resources associated with this request context. This should be the final action for any request.

flush():Void

Flushes any buffered output to the client.

writeByte(c:Int):Void

Writes a single byte to the response body. Requires beginWrite() to have been called first.

Parameters:

c

The byte to write.

@:value({ len : -1, pos : 0 })writeFullBytes(bytes:Bytes, pos:Int = 0, len:Int = -1):Void

Writes a chunk of bytes to the response body. Requires beginWrite() to have been called first.

Parameters:

bytes

The Bytes buffer to write from.

pos

The starting position in the buffer.

len

The number of bytes to write.

writeInput(i:Input, ?bufsize:Int):Void

Writes the content of an Input stream to the response body. Requires beginWrite() to have been called first.

Parameters:

i

The Input stream to read from.

bufsize

The size of the buffer to use for copying.

writeResponse(response:Response):Void

Writes a complete Response object to the client in a single operation. This method should not be used if a manual stream has been started with beginWrite().

Parameters:

response

The complete Response object to send.

writeString(s:String, ?encoding:Encoding):Void

Writes a string to the response body. Requires beginWrite() to have been called first.

Parameters:

s

The String to write.

encoding

The character encoding to use.