CompressingOkHttpTransport
public class CompressingOkHttpTransport implements HttpTransport
io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:69–499Compressing Ok HTTP 传输层,为框架提供通用类型与基础能力。位于 io.agentscope.examples.compression.extra 包,实现 HttpTransport。核心成员包括 execute、stream、close、getClient、getTransportConfig、getCompressionConfig。
OkHttp transport implementation with compression support.
This class extends the standard HTTP transport functionality with:
-
Request body compression (GZIP, Brotli, Zstd)
-
Response body decompression
-
SSE stream decompression
Usage example:
`CompressionConfig compressionConfig = CompressionConfig.builder()
.enableGzipCompression()
.build();
CompressingOkHttpTransport transport = CompressingOkHttpTransport.builder()
.compressionConfig(compressionConfig)
.build();
// Use with your model client
DashScopeChatModel model = DashScopeChatModel.builder()
.apiKey("your-api-key")
.httpTransport(transport)
.build();
`
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | CompressingOkHttpTransport的构建器。 Builder for CompressingOkHttpTransport. |
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
HEADER_CONTENT_ENCODINGstaticfinal | String | 请求头内容 ENCODING字段。 HTTP header name for content encoding. |
HEADER_ACCEPT_ENCODINGstaticfinal | String | 请求头 ACCEPT ENCODING字段。 HTTP header name for accepted encodings. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public CompressingOkHttpTransport() | 创建新的CompressingOkHttpTransport 使用默认配置。 Create a new CompressingOkHttpTransport with default configuration. |
public CompressingOkHttpTransport(HttpTransportConfig transportConfig, CompressionConfig compressionConfig) | 创建新的CompressingOkHttpTransport 使用自定义配置。 Create a new CompressingOkHttpTransport with custom configuration. |
public CompressingOkHttpTransport(OkHttpClient client, HttpTransportConfig transportConfig, CompressionConfig compressionConfig) | 初始化 `CompressingOkHttpTransport` 实例。 Create a new CompressingOkHttpTransport with an existing OkHttpClient. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public HttpResponse execute(HttpRequest request) throws HttpTransportException | 设置执行。 Performs the execute operation. |
public Flux<String> stream(HttpRequest request) | 设置流。 Performs the stream operation. |
public void close() | 关闭连接并释放相关资源。 Releases resources and connections. |
public OkHttpClient getClient() | 获取客户端。 Get the underlying OkHttpClient instance. |
public HttpTransportConfig getTransportConfig() | 获取传输层配置。 Get the transport configuration. |
public CompressionConfig getCompressionConfig() | 获取压缩配置。 Get the compression configuration. |
public static Builder builder()static | 创建用于CompressingOkHttpTransport的构建器。 Create a new builder for CompressingOkHttpTransport. |
字段详情Field Detail
HEADER_CONTENT_ENCODING
public static final String HEADER_CONTENT_ENCODING
请求头内容 ENCODING字段。声明为 public static final String HEADER_CONTENT_ENCODING。
HTTP header name for content encoding.
io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:78HEADER_ACCEPT_ENCODING
public static final String HEADER_ACCEPT_ENCODING
请求头 ACCEPT ENCODING字段。声明为 public static final String HEADER_ACCEPT_ENCODING。
HTTP header name for accepted encodings.
io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:81构造器详情Constructor Detail
CompressingOkHttpTransport
public CompressingOkHttpTransport()
创建新的CompressingOkHttpTransport 使用默认配置。
Create a new CompressingOkHttpTransport with default configuration.
io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:90–92CompressingOkHttpTransport
public CompressingOkHttpTransport(HttpTransportConfig transportConfig, CompressionConfig compressionConfig)
创建新的CompressingOkHttpTransport 使用自定义配置。
Create a new CompressingOkHttpTransport with custom configuration.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
transportConfig | HttpTransportConfig | 传输层配置。the transport configuration |
compressionConfig | CompressionConfig | 压缩配置。the compression configuration |
io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:100–105CompressingOkHttpTransport
public CompressingOkHttpTransport(OkHttpClient client, HttpTransportConfig transportConfig, CompressionConfig compressionConfig)
初始化 CompressingOkHttpTransport 实例。
Create a new CompressingOkHttpTransport with an existing OkHttpClient.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
client | OkHttpClient | OkHttpClient 到使用。the OkHttpClient to use |
transportConfig | HttpTransportConfig | 传输层配置(类型 `HttpTransportConfig`)。the transport configuration (used for reference only) |
compressionConfig | CompressionConfig | 压缩配置。the compression configuration |
io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:114–121方法详情Method Detail
execute
public HttpResponse execute(HttpRequest request) throws HttpTransportException
设置执行。
Performs the execute operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | HttpRequest | 请求(类型 `HttpRequest`)。The request. |
HttpResponseHttpTransportException可能抛出 `HttpTransportException`。Thrown when the operation cannot be completed.
io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:136–145stream
public Flux<String> stream(HttpRequest request)
设置流。
Performs the stream operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | HttpRequest | 请求(类型 `HttpRequest`)。The request. |
Flux<String>io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:147–248close
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
io/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:250–254getClient
public OkHttpClient getClient()
获取客户端。
Get the underlying OkHttpClient instance.
OkHttpClientio/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:261–263getTransportConfig
public HttpTransportConfig getTransportConfig()
获取传输层配置。
Get the transport configuration.
HttpTransportConfigio/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:270–272getCompressionConfig
public CompressionConfig getCompressionConfig()
获取压缩配置。
Get the compression configuration.
CompressionConfigio/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:279–281builder
public static Builder builder()
创建用于CompressingOkHttpTransport的构建器。
Create a new builder for CompressingOkHttpTransport.
Builderio/agentscope/examples/compression/extra/CompressingOkHttpTransport.java:428–430嵌套类详情Nested Class Detail
Builder
public static class BuilderCompressingOkHttpTransport的构建器。位于 io.agentscope.examples.compression.extra 包。核心成员包括 transportConfig、compressionConfig、client、enableGzipCompression、build。
Builder for CompressingOkHttpTransport.