A local HTTP server to point a provider client at, so a test exercises the client's real request and response handling - including streaming - without a network or an API key.
It is the JDK's com.sun.net.httpserver.HttpServer on an ephemeral port, so it adds no dependency.
holdOpen and streamThenHold are handlers that never finish answering, for checking that a client's call can be interrupted (see ProviderModuleChecks.assertCancelsWhenInterrupted). Handlers run on virtual threads, so this needs JDK 21 (see docs/guide/writing-a-provider.md).
Holds the request open without answering until the enclosing withServer block ends - a provider that never replies, for checking that a client's call can be interrupted.
Holds the request open without answering until the enclosing withServer block ends - a provider that never replies, for checking that a client's call can be interrupted.
An OpenAI-format streaming body: one SSE data: event per chunk of content, the last carrying finish_reason and usage, then data: [DONE].
An OpenAI-format streaming body: one SSE data: event per chunk of content, the last carrying finish_reason and usage, then data: [DONE].
Attributes
def sendJsonResponse(exchange: HttpExchange, statusCode: Int, body: String): Unit
Sends a JSON response with the given status code and body.
Sends a JSON response with the given status code and body.
Attributes
def sendSseResponse(exchange: HttpExchange, body: String): Unit
Sends a 200 SSE (text/event-stream) response with the given raw body.
Sends a 200 SSE (text/event-stream) response with the given raw body.
Attributes
def streamThenHold(exchange: HttpExchange, firstEvent: String, contentType: String): Unit
Starts a 200 streaming response, sends firstEvent (one complete event in the provider's stream format), then holds the response open like holdOpen.
Starts a 200 streaming response, sends firstEvent (one complete event in the provider's stream format), then holds the response open like holdOpen.
Attributes
def withServer(path: String)(handler: HttpExchange => Unit)(test: String => Any): Unit
Starts a local HTTP server with handler bound to path, runs test with the server's base URL (http://localhost:<port>, no trailing slash), then stops the server - also when test throws, whose exception is then rethrown.
Starts a local HTTP server with handler bound to path, runs test with the server's base URL (http://localhost:<port>, no trailing slash), then stops the server - also when test throws, whose exception is then rethrown.