Class CopilotRequestHandler
java.lang.Object
com.github.copilot.CopilotRequestHandler
The base class for SDK consumers who want to observe or replace the LLM
inference requests the runtime issues (for both CAPI and BYOK providers).
When set as the requestHandler on
CopilotClientOptions, the runtime routes its
model-layer HTTP and WebSocket traffic through this handler instead of
issuing the calls itself. Subclass and override sendRequest(HttpRequest, CopilotRequestContext) to
mutate or replace HTTP calls, or openWebSocket(CopilotRequestContext) to mutate the
handshake or return a fully custom CopilotWebSocketHandler.
- Since:
- 1.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected HttpClientTheHttpClientused to forward HTTP requests.protected CopilotWebSocketHandlerReturns a per-connection WebSocket handler for a WebSocket request.protected HttpResponse<InputStream> sendRequest(HttpRequest request, CopilotRequestContext ctx) Forwards an HTTP request and returns the upstream response.
-
Constructor Details
-
CopilotRequestHandler
public CopilotRequestHandler()
-
-
Method Details
-
httpClient
TheHttpClientused to forward HTTP requests. Override to supply a custom client (proxy, TLS, timeouts). The default never follows redirects, so 3xx responses are forwarded verbatim.- Returns:
- the HTTP client
-
sendRequest
protected HttpResponse<InputStream> sendRequest(HttpRequest request, CopilotRequestContext ctx) throws Exception Forwards an HTTP request and returns the upstream response. The default sendsrequestthroughhttpClient()and cancels the in-flight call when the runtime cancels the request. Override to mutate the request before sending, post-process the response, or replace the call entirely.- Parameters:
request- the request built from the runtime's inference requestctx- the per-request context- Returns:
- the upstream response, with the body as an
InputStream - Throws:
Exception- if the request could not be completed
-
openWebSocket
Returns a per-connection WebSocket handler for a WebSocket request. The default opens a transparent forwarding connection to the request URL. Override to mutate the handshake (viactx) or return a fully custom handler.- Parameters:
ctx- the per-request context- Returns:
- the WebSocket handler
- Throws:
Exception- if the handler could not be created
-