HTTP client abstraction for LangChain4j with synchronous/asynchronous execution and Server-Sent Events (SSE) streaming support
A decorator that wraps any HttpClient implementation to add logging functionality.
/**
* Decorator for HttpClient that adds logging capabilities.
* Automatically masks sensitive headers like Authorization, X-API-Key, etc.
* Internal API - implementation details may change.
*/
public class LoggingHttpClient implements HttpClient {
/**
* Creates a logging HTTP client with default logger.
*
* @param delegateHttpClient the underlying HTTP client to wrap
* @param logRequests whether to log HTTP requests
* @param logResponses whether to log HTTP responses
*/
public LoggingHttpClient(HttpClient delegateHttpClient, Boolean logRequests, Boolean logResponses);
/**
* Creates a logging HTTP client with custom logger.
*
* @param delegateHttpClient the underlying HTTP client to wrap
* @param logRequests whether to log HTTP requests
* @param logResponses whether to log HTTP responses
* @param logger the SLF4J logger to use for logging
*/
public LoggingHttpClient(HttpClient delegateHttpClient, Boolean logRequests, Boolean logResponses, Logger logger);
}The LoggingHttpClient automatically masks sensitive headers to prevent accidental logging of secrets.
The following headers are automatically masked:
AuthorizationX-API-KeyX-Auth-Tokenapi-key (case-insensitive)For headers with values of 7 or more characters:
...For headers with values shorter than 7 characters:
...Original: Bearer sk-1234567890abcdef
Masked: Beare...ef
Original: 12345
Masked: ...
Original: api_key_abc123xyz789
Masked: api_k...89Errors during logging itself are caught and logged at WARN level:
WARN Exception occurred while logging HTTP request: <error message>
WARN Exception occurred while logging HTTP response: <error message>INFO HTTP request:
- method: POST
- url: https://api.example.com/data
- headers: [Authorization: Beare...45]
- body: {"key":"value"}INFO HTTP response:
- status code: 200
- headers: [Content-Type: application/json]
- body: {"result":"success"}DEBUG ServerSentEvent { event = null, data = "Hello" }
DEBUG ServerSentEvent { event = null, data = "world" }
DEBUG ServerSentEvent { event = "done", data = "" }Install with Tessl CLI
npx tessl i tessl/maven-dev-langchain4j--langchain4j-http-client@1.11.0