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.
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 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.